Android - 如何在具有特定位置、缩放级别和标记的 Android 应用程序中启动 Google 地图意图 [英] Android - How to launch Google map intent in android app with certain location, zoom level and marker

查看:30
本文介绍了Android - 如何在具有特定位置、缩放级别和标记的 Android 应用程序中启动 Google 地图意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

地图意图不适用于特定缩放级别以及自定义标记

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);

有人知道怎么回事吗?或者怎么做?我想在特定的缩放级别使用自定义标签标记显示某些 (lat,lng) 的地图.

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.

推荐答案

尝试以下解决方案:

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);

功劳在这里:答案

我认为问题与标签中的空格有关.编码查询字符串将通过用有效字符替换空格来消除问题

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

这篇关于Android - 如何在具有特定位置、缩放级别和标记的 Android 应用程序中启动 Google 地图意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆