112

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Specur
  • 3,240
  • 4
  • 23
  • 25

7 Answers7

262

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.

Kenton Price
  • 5,229
  • 4
  • 23
  • 21
  • After implementing this URI i have problems setting the zoom. It seems to be obsolete now – 0xPixelfrost Apr 22 '12 at 16:06
  • 9
    @mmm...: You'll need to change the ?z to an &z. You can only have one ? in a uri. BAD: geo:N,M?z=10?q=N,M(Place) GOOD: geo:N,M?z=10&q=N,M(Place) – Josh Jun 27 '12 at 21:48
  • No zoom still doesn't work (but the label thing does). Also if maps can't find anything relevant (even though we supply it with the label) it will show a toast error. This solution works but only semi optimal. – Warpzit Dec 20 '12 at 14:15
  • That was special, Droider. Instead of and you enter the longitudinal and latitudinal value you require. – Kenton Price Feb 25 '13 at 11:02
  • 3
    Zoom is ignored because this is a simple query rather than a geointent. What happens here is actually a plain query that is sent to Google, and then the server responds with a "search result" corresponding to it. You can try searching for ,(Label+Name) on maps.google.com and get the same result – robpvn Mar 14 '13 at 12:06
  • 4
    Using this(or any of the other methods here which involve a labeled query) completely ignores the geopoint in the `geo:` portion, lke robpvn pointed out. In some cases the query will fail using lat/long, and then you just get a "no results" toast instead of falling back to geopoint. Not very useful for any sort of GIS app. – Geobits Jul 12 '13 at 19:58
  • This functionality was broken in new Google Maps 7.x, see too https://code.google.com/p/android/issues/detail?id=58507 – ATom Aug 03 '13 at 18:05
  • There's official documentation on: http://developer.android.com/guide/components/intents-common.html#Maps – moxi Feb 08 '16 at 02:46
  • 1
    this doesn't work any more .. the label does not show – user2297550 Mar 27 '19 at 11:00
  • how to do it with multiple of latlong andorid – Ahmad Arslan Dec 03 '19 at 10:09
  • this is working, Android12, Uri gmmIntentUri = Uri.parse("geo:"+latitude+","+longitude+"?z="+zoom+"&q="+latitude+","+longitude); – user1644002 May 16 '22 at 21:23
51

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);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
45

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);
Community
  • 1
  • 1
xorgate
  • 2,244
  • 1
  • 24
  • 36
  • 2
    This functionality was broken in new Google Maps 7.x, see too https://code.google.com/p/android/issues/detail?id=58507 – ATom Aug 03 '13 at 18:07
6

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);
The HCD
  • 492
  • 8
  • 18
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
joshuau
  • 21
  • 2
1

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);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fate Chang
  • 197
  • 3
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John J Smith
  • 11,435
  • 9
  • 53
  • 72