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

后端 未结 4 747
北荒
北荒 2020-11-30 01:16

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

    float lat = 40.714728f;
    float lng = -73.998672f;

    String maplLabel = \"A         


        
相关标签:
4条回答
  • 2020-11-30 01:46
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + location.getLatitude() + "," + location.getLongitude()));
    startActivity(intent);
    
    0 讨论(0)
  • 2020-11-30 01:55

    Show location in maps application:

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    String data = String.format("geo:%s,%s", latitude, longitude);
    if (zoomLevel != null) {
        data = String.format("%s?z=%s", data, zoomLevel);
    }
    intent.setData(Uri.parse(data));
    startActivity(intent);
    
    0 讨论(0)
  • 2020-11-30 02:04

    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

    0 讨论(0)
  • 2020-11-30 02:06

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

    It has pretty much everything related to the Maps intent.

    0 讨论(0)
提交回复
热议问题