How do I show a marker in Maps launched by geo URI Intent?

AndroidGoogle MapsAndroid IntentAndroid Maps

Android Problem Overview


I have a application where I want to show different locations (one at the time, picked by user input) by launching Google Maps with their specific geo coordinates.

I'm currently using this (with real lat. and long. values of course):

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?z=17"));
startActivity(intent);

It's quite exactly what I want, except that it doesn't show any indicator or marker for the specified point. It only centers at it's location.

Is there some way to get the marker or something else included without using a MapView?

Android Solutions


Solution 1 - Android

Try this:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);

You can omit (Label+Name) if you don't want a label, and it will choose one randomly based on the nearest street or other thing it thinks relevant.

Solution 2 - Android

##There are many more options to launch a Google map using an intent...

   Double myLatitude = 44.433106;
   Double myLongitude = 26.103687;
   String labelLocation = "Jorgesys @ Bucharest";

###1)

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<" + myLatitude  + ">,<" + myLongitude + ">?q=<" + myLatitude  + ">,<" + myLongitude + ">(" + labelLocation + ")"));
    startActivity(intent);

###2)

String urlAddress = "http://maps.google.com/maps?q="+ myLatitude  +"," + myLongitude +"("+ labelLocation + ")&iwloc=A&hl=es";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
    startActivity(intent);

###3)

   String urlAddress = "http://maps.googleapis.com/maps/api/streetview?size=500x500&location=" + myLatitude  + "," + myLongitude + "&fov=90&heading=235&pitch=10&sensor=false";
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
        startActivity(intent);

Solution 3 - Android

The accepted answer is correct, except when your label has an ampersand (&) in it.

Looking at A Uniform Resource Identifier for Geographic Locations ('geo' URI):

Section 5.1 states:

> if the final URI is to include a 'query' component, add the component delimiter "?" to the end of the result, followed by the encoded query string.

Unfortunately for us, doing this will also escape the '=' which is not what we want.

We should do this:

String label = "Cinnamon & Toast";
String uriBegin = "geo:12,34";
String query = "12,34(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery;
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);

Solution 4 - Android

This string works well for me:

String geoUriString="geo:"+lat+","+lon+"?q=("+head+")@"+lat+","+lon;
Uri geoUri = Uri.parse(geoUriString);
Log.e(TAG, "String: "+geoUriString);
Intent mapCall  = new Intent(Intent.ACTION_VIEW, geoUri);
startActivity(mapCall);

Solution 5 - Android

Try appending (LocationMarkerName) to the geo: uri. For example, "geo:,?z=17(LocationMarkerName)"

In Google Maps on Android searching for 23.0980,30.6797 (NamedMarker), it seems to centre the map and position a marker with name NamedMarker at that position.

Solution 6 - Android

I just confirmed the following snippet from @Kenton Price still works on Android 4.4 (KitKat):

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);

Solution 7 - Android

I have only used Overlays with the MapView for drawing markers on top of a map. If your view is showing your map, it might be possible to simply draw your marker at the centre of the screen, in the same way as you would draw any image on a View.

However, the marker wouldn't be linked to the actual map coordinates, but if it's just a static view, then this might do.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSpecurView Question on Stackoverflow
Solution 1 - AndroidKenton PriceView Answer on Stackoverflow
Solution 2 - AndroidJorgesysView Answer on Stackoverflow
Solution 3 - AndroidxorgateView Answer on Stackoverflow
Solution 4 - AndroidThe HCDView Answer on Stackoverflow
Solution 5 - AndroidjoshuauView Answer on Stackoverflow
Solution 6 - AndroidFate ChangView Answer on Stackoverflow
Solution 7 - AndroidJohn J SmithView Answer on Stackoverflow