这是怎么回事。我想启动一个外部 Activity 来显示地理坐标,而不是在我的应用程序中实现 Google map 。目前我手头有太多东西,我不想经历实现 map 的麻烦。因此,是否可以将参数传递给外部 map Activity ,类似于我们对短信、电话、相机等所做的?
非常感谢!
最佳答案
你可以用这个命令来做到这一点:
private void openMapGeo(String latitude, String longitude) {
Intent intent2 = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + latitude + ","
+ longitude + "?z=17&q=" + latitude + "," + longitude));
// z stands for zoom level
// replace the q with a search string works too. Example:
// intent2 = new Intent(Intent.ACTION_VIEW,
// Uri.parse("geo:0,0?q=Tokyo"));
startActivity(intent2);
}
另一种方法是使用 map 网站 url。这将询问用户是否要打开 map 应用程序(如果已安装)或浏览器:
private void openMapUrl(String latitude, String longitude) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/?q=" + latitude + "," + longitude));
startActivity(intent);
}
此处还有一些其他示例:https://github.com/pboos/GoogleMapExamples (看看里面的 Presentation.pdf 文件)
编辑:
如果安装了 google maps 应用程序,要使用以上两个功能,请执行此操作(以上两个功能也需要存在):
private void openMap(String latitude, String longitude) {
try {
ApplicationInfo info = getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 );
openMapGeo(latitude, longitude);
} catch(PackageManager.NameNotFoundException e) {
openMapUrl(latitude, longitude);
}
}
关于java - 启动外部 Activity 以显示 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9187646/