简体   繁体   English

Android - 如何在Android应用中使用特定位置,缩放级别和标记启动Google地图意图

[英]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 Map Intent不使用特定缩放级别以及自定义标记

    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. 我想在特定缩放级别使用自定义标签标记显示某些(lat,lng)的地图。

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 对查询字符串进行编码将通过将空格替换为有效字符来消除此问题

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);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + location.getLatitude() + "," + location.getLongitude()));
startActivity(intent);

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

It has pretty much everything related to the Maps intent. 它几乎包含与地图意图相关的所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在标记上单击动画在最大缩放级别上设置Google地图 - how to set google map on max zoom level with animation on marker click in android 如何从具有最高缩放级别的特定位置启动我的Android应用程序的地图活动(谷歌地图api) - How to start the map activity (google map api) of my android application from a specific location with a highest zoom level 如何在谷歌地图上移动地图,但在Android中将标记保留为当前位置? - how to moves map on google map but keep marker as current location in android? 谷歌地图意图没有动画到Android应用程序中的当前位置…? - google map intent not animate to current location in android app…? Android-如何在行驶模式下启动Google Map Intent? - Android - How to launch Google map intent in driving mode? 如何在Android中动态设置谷歌地图上的缩放级别? - How set zoom level on google map dynamically in android? Google Map Android应用程序上的缩放比例更大 - Bigger zoom level on Google Map Android application 在Android的Google地图中动态设置缩放级别 - Setting zoom dynamically level in Google map in android 如何解决Android中的Google Map缩放级别问题 - How to solve Google Map zoom level issue in android 在Android的Google地图中自动设置缩放级别 - Setting zoom level automatically in Google map in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM