[英]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.