【发布时间】:2019-08-16 03:24:42
【问题描述】:
我的应用中有一个地址参数,例如“921 Beverly Hills, california, CA-09001” 点击这个后,我希望谷歌地图打开并显示这个确切地址的注释。我怎么做? 有什么线索吗?
【问题讨论】:
标签: android android-intent android-location android-maps android-googleapiclient
我的应用中有一个地址参数,例如“921 Beverly Hills, california, CA-09001” 点击这个后,我希望谷歌地图打开并显示这个确切地址的注释。我怎么做? 有什么线索吗?
【问题讨论】:
标签: android android-intent android-location android-maps android-googleapiclient
有很多资源可以帮助您学习这是一个示例。在真正的应用程序中,您可能希望使用自己的地图活动来处理意图;也许添加边界和相机以放大或其他...
Location sf = new Location("");
sf.setLatitude(37.7749);
sf.setLongitude(-122.4194);
requestLocation("your address");
public void requestLocation(Location location) {
// Create a Uri from an intent string. Use the result to
// create an Intent.
Uri gmmIntentUri = Uri.parse("geo:" + location.getLatitude() + "," + location.getLongitude());
// Create an Intent from gmmIntentUri. Set the action to
// ACTION_VIEW
Intent mapIntent = new Intent(Intent.ACTION_VIEW,
gmmIntentUri);
// Make the Intent explicit by setting the Google Maps
// package
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(mapIntent, REQUEST_LOCATION);
}
}
public void requestLocation(String address) {
// Create a Uri from an intent string. Use the result to create
//an Intent.
Uri gmmIntentUri = Uri.parse("geo:" + address);
// Make the Intent explicit by setting the Google Maps
// package
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(mapIntent, REQUEST_LOCATION);
}
}
【讨论】:
您可以在此处找到有关如何使用意图通过地址启动 Google 地图的概述:
https://developers.google.com/maps/documentation/urls/android-intents
【讨论】: