我的应用程序中有一个地址参数说“921 Beverly Hills,California,CA-09001”点击这个我想要谷歌地图打开并显示这个确切地址的注释。我怎么做?任何线索?
有很多资源可以帮助你,这是一个样本。在真实的应用程序中,您可能希望使用自己的地图活动来处理意图;也许添加边界和相机放大或任何...
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