At first I know that there are several similar questions on StackOverflow. Curriently I use the geo scheme for addressing points which can be handled by other apps.
Like in the example of the Android documentation (by the way it seems to be outdated the RFC it out!) I tried to use something like this:
geo:50.95144,6.98725?q=50.95144,6.98725%20(Disneyland)
So I get a intent chooser where I can select an App which showed me in case of Google Maps Disneyland with a marker on it. Now it seems that an update was installed which removes that support. I just get the message that this place cannot been found.
I tried to understand the RFC 5870 which defines the 'geo' URI Scheme. I don't get it exactly. It is correct that it is not possible at all to define a lable?
How can I link now a position to Google Maps?
The WhatsApp intent is:
START u0 {act=android.intent.action.VIEW
cat=[android.intent.category.BROWSABLE]
dat=https://maps.google.com/maps?q=loc:lat,lng+(You)&rlz=1Y1TXLS_enDE543DE543
flg=0x3000000 cmp=com.android.browser/.BrowserActivity (has extras)}
from pid 2115
So if you use the following intent URI:
String geoUri = "http://maps.google.com/maps?q=loc:" + lat + "," + lng + " (" + mTitle + ")";
...it should behave like WhatsApp. Furthermore it seems that some other geo apps trigger on this intent too. But it doesn't work for all geo apps!
This is working on the latest Google Maps v7.1 tested on my Nexus 4.
public static void launchGoogleMaps(Context context, double latitude, double longitude, String label) {
String format = "geo:0,0?q=" + Double.toString(latitude) + "," + Double.toString(longitude) + "(" + label + ")";
Uri uri = Uri.parse(format);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
Like in the example of the Android documentation (by the way it seems to be outdated the RFC it out!) I tried to use something like this
The four sample constructions in the documentation are:
geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city
You will notice that none of those have a "label" in parentheses, separated by a space from the rest of the Uri.
Now it seems that an update was installed which removes that support
That "support", if it existed before, was undocumented, and you should not have been relying upon it. You will also note that there are many mapping applications for Android, any of which the user could choose for a geo: Intent -- did you test all of these to see if your undocumented capability worked on all of them?
It is correct that it is not possible at all to define a lable?
I do not see any evidence of your label-in-parentheses syntax in that RFC. Though, I agree, these IETF RFC tend to be difficult to read.
How can I link now a position to Google Maps?
Drop the label-in-parentheses:
geo:50.95144,6.98725?q=50.95144,6.98725
And, since you don't need the ? part anymore, you could use:
geo:50.95144,6.98725
If your real question is "how can I link now a position to Google Maps and have it show my own label", probably you can't.
You are welcome to embed a mapping engine into your app (e.g., Google's Maps V2 for Android), in which case you can mark up the map to the limits of that engine's API for it. I would expect any serious mapping engine to support adding markers with some sort of label.
Related
I am using Google Maps turn by turn navigation in my app to navigate from the current location to a given address. It works fine, my only problem is that I cannot set up avoid tolls/highways/ferries options via intent.
I followed google descriptions here: https://developers.google.com/maps/documentation/android-api/intents#launch_turn-by-turn_navigation
My code is the following with avoid tolls parameter:
String navigation = "google.navigation:q=" + latLng.latitude + "," + latLng.longitude + "&avoid=t";
Uri uri = Uri.parse(navigation);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
Navigation starts fine, but it doesn't take notice of the avoid tolls parameter, it opens the driving route through roads, where tolls must be paid.
I also tried &dirflg=t and &avoid=tolls parameters, but no result.
Does anybody have some solution for this?
Thank you!
I think it's a bug in some of the android implementations on some devices.
I have the same problem. The same code runs fine on an A3 (2016), but not on an Xcover 3. Both on Lollipop (API 22) but on slightly different versions (newer on the A3). Maybe an update will help.
I'm creating an Android app for a chinese client and they need map integration, so Google maps is not an option since all Google services are blocked in China. I'm trying to use Baidu maps, which is called Baidu LBS (location-based services) cloud.
Getting a basic map with no overlays to work was relatively easy. The process is described here (in Chinese, but the code speaks for itself if you don't understand the language). Downloading the latest Baidu Android SDK (v3.2.0 at time of writing) and integrating it into my Eclipse project as a library was no problem, but don't trust the documentation in that link too much even though it is the official one. Their examples often contain code that wouldn't even compile. The name of the .jar file for example was completely different from what you see in their screenshot.
Oh and also their .jar library is obfuscated which is super annoying to work with :-(
I needed to register a Baidu account and go to their control center to generate a key. To create an access key ("ak") for mobile you need to enter the SHA1 fingerprint of the keystore which signs your app, followed by the package name specified in your manifest.
Then I added the generated key to my manifest under the tag
<meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="xxx...xxx" />
I then copied code from their sample project's CloudSearchActivity because I have specific coordinates that I would like to display. I implemented the CloudListener interface as shown:
#Override
public void onGetSearchResult(final CloudSearchResult result, final int error)
{
Log.w("onGetSearchResult", "status=" + result.status + ". size=" + result.size + ". total=" + result.total + ". error=" + error);
if(null != result && null != result.poiList && 0 < result.poiList.size())
{
mBaiduMap.clear();
final BitmapDescriptor bitmapDescriptor=BitmapDescriptorFactory.fromResource(R.drawable.icon_address_grey);
LatLng latitudeLongitude;
LatLngBounds.Builder builder=new Builder();
for(final CloudPoiInfo info : result.poiList)
{
latitudeLongitude=new LatLng(info.latitude, info.longitude);
final OverlayOptions overlayOptions=new MarkerOptions().icon(bitmapDescriptor).position(latitudeLongitude);
mBaiduMap.addOverlay(overlayOptions);
builder.include(latitudeLongitude);
}
final LatLngBounds bounds=builder.build();
MapStatusUpdate mapStatusUpdate=MapStatusUpdateFactory.newLatLngBounds(bounds);
mBaiduMap.animateMapStatus(mapStatusUpdate);
}
}
And I added code to launch a query (also copied from their sample project):
#Override
public View onCreateView(final LayoutInflater layoutInflater, final ViewGroup viewGroup,
final Bundle savedInstanceState)
{
// initialize needs to be called
SDKInitializer.initialize(getApplication());
CloudManager.getInstance().init(MyFragment.this);
view=(ViewGroup)layoutInflater.inflate(R.layout.fragment_map, viewGroup, false);
mMapView=(MapView)view.findViewById(R.id.baiduMapView);
mBaiduMap=mMapView.getMap();
NearbySearchInfo info=new NearbySearchInfo();
info.ak="xxx...xxx";
info.geoTableId=12345;
info.tags="";
info.radius=30000;
info.location="116.403689,39.914957";
CloudManager.getInstance().nearbySearch(info);
return view;
}
Unfortunately I keep getting a status value of 102 from the server (according to this API page that means STATUS_CODE_SECURITY_CODE_ERROR. Now I don't know what to do.
Things that I don't understand:
Why do I need to repeat my access key ("ak") when building the query? Is it not enough to have it in the manifest once?
What is this "geoTableId" value in the query supposed to be?
Any ideas?
After many hours of research I have made some progress on the open questions.
The reason for the "ak" field in a cloud search query is not duplication, it is in fact a different access key. Somewhere in a hidden place Baidu says that access keys "for mobile" will not work for these cloud searches, you need an ak "for server". So the solution is to go back to the Baidu control center and create another key "for server". This key needs to be used in the query, while the "for mobile" key needs to remain in the manifest.
geoTableId is an identifier of your account, not unsimilar to the access keys. It is a (currently) 5 digit number that you need to obtain in the Baidu control center. The other keys were generated in the tab titled "API控制台" (API control desk), but for the geoTableId you need to switch to the tab called "数据管理" (data management). There I think I needed to press the "创建" (~create) button on top left, then enter a name, select "是" (yes) where they ask if this is for release (not sure about that translation) and then click "保存" (save). After this, your freshly generated number is displayed in the top field in parentheses behind the name you chose just now.
These steps have allowed me to send "successful" queries where the server answers with status 0 (STATUS_CODE_SUCCEED). However, so far all the answers I get are empty, I have yet to find a query which produces a non-empty answer. If anyone manages to do that, please let me know!
I am displaying a location on Google map by passing latitude longitude values.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:0,0?q=" + (" "+dblLatitude+", "+dblLongitude+" ")));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
setContentView(R.layout.map_locate);
}
Its working fine for me. But I also want to show text on above the located point. Any idea how to pass the text dynamically like I am passing lat, long values?
To show a label on Google Maps application you have to add it in brackets after coordinates.
See this answer: https://stackoverflow.com/a/7405992/2183804
You can put extra data into the intent object using e.g. the putExtra(String,String) method on the intent object.
As you firing an intent to turn on the native Google Maps Application. I don't think that what you are trying to achieve is possible. AFAIK all you can add to the desired location is an icon.
If you want to add to it more functionality you would have to develop your own map application.
UPDATE:
To develop you own map, you can take a look at this blog post I wrote on that matter:
Google Maps API V2
If you have questions don't hesitate to ask.
I am new to android and developing a navigation based application for android.My question is I want to show a route with multiple way-points between source and destination node in Google maps and I don't know how to do it. I have search for this but most of the results are for two points.
Please help me to solve my problem
e.g:- when app user submits the destination with some way-points the map should display the route from the source to destination with those way-points on the phone.
Thanks !
I don't think the Maps intent offers those capabilities, but you do have some other options
Better but more work
1)Create your own map activity that displays routes for multi-location(using a mapview and overlays). Here is an example of how to convert the kml file to a route
Quicker and Easier
2)Create a simple webview (or you can just intent a new one with a given url) and dynamically build the url for a google maps api request with waypoints. See Google's website for documentation on getting a map with routes via waypoints.
"I have search for this but most of the results are for two points." You already found everything you need to do this.
For this, you're not "drawing through the waypoints along the way," you're actually going to have to draw a route between 2 points for each waypoint you have:
IE. You want to get from point A to point D, and on the way there are points B and C. The solution is to draw a route from A to B, B to C, and finally C to D.
You can use the map intent like this:
String address = "http://maps.google.com/maps?daddr=" + "Latitude" + "," + "Longitude" + "+to:" +"Latitude" + "," + "Longitude";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(address));
startActivity(intent);
in this case the start point will be your current location and you can add as many intermediate points as you want using "+to:"
Im having problems porting some functions of Iphone application to Android.
Basically iphone google map app that is invoked from this app looks like this
I have tried to copy similar behaviour using this pseudo code
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+LAT_POSITION+","+LONG_POSITION+"&daddr="+Lat+","+Lon + "&dirflg=w"));
startActivity(intent);
what it does it brings the android map app in this form
so then when i click show map i get
and then when i press back twice i get this
my questions are.
How I can get the (car,public,walk) controls overlay the map? just like in iphone app - on one screen (other elements too if possible)
additional question..
How I can enable showing map by default? (instead of textual directions, this is happening in android 2.2 - I have checked on samsung galaxy with froyo) , In 4.0 (emulator) the map is showing by default but still there are no overlay controls (car,public,walk).
You can use setComponent to explicitly tell the Maps app to use com.google.android.maps.MapsActivity to resolve the intent:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + LAT_POSITION + "," + LONG_POSITION +
"&daddr=" + lat + "," + lon + "&dirflg=w"));
intent.setComponent(new ComponentName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
startActivity(intent);
You should get the directions overlay but I'm not sure it will draw the route until the user hits "Go".
Of course this is "non API" and assumes that Maps is installed on the device and that Google will not change the internal packgage or class name for MapsActivity.