Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to launch Google map intent in android app with certain location, zoom level and marker

Map Intent not working with specific zoom level as well as custom marker

    float lat = 40.714728f;     float lng = -73.998672f;      String maplLabel = "ABC Label";     final Intent intent = new Intent(android.content.Intent.ACTION_VIEW,             Uri.parse("geo:0,0?q="+lat+","+lng+"&z=16 (" + maplLabel + ")"));     startActivity(intent); 

Anybody know what is wrong? or how to do so? I want to show map of certain (lat,lng) with a custom label-marker at a specific zoom level.

like image 970
umirza47 Avatar asked Oct 24 '12 16:10

umirza47


2 Answers

Try the following solution:

double latitude = 40.714728; double longitude = -73.998672; String label = "ABC Label"; String uriBegin = "geo:" + latitude + "," + longitude; String query = latitude + "," + longitude + "(" + label + ")"; String encodedQuery = Uri.encode(query); String uriString = uriBegin + "?q=" + encodedQuery + "&z=16"; Uri uri = Uri.parse(uriString); Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri); startActivity(intent); 

Credit goes here: Answer

I believe the problem had to do with the spaces in your label. Encoding the query string will eliminate the issue by replacing the spaces with valid characters

like image 166
dymmeh Avatar answered Oct 03 '22 21:10

dymmeh


http://developer.android.com/guide/components/intents-common.html#Maps

It has pretty much everything related to the Maps intent.

like image 32
Naren Avatar answered Oct 03 '22 20:10

Naren