2014-09-03 45 views
-2

我想点击一个链接时打开自带谷歌地图应用,所以我这样做:没有浏览器的谷歌地图应用的意图

String urlAddress = "http://maps.google.com/maps?q="+ mylat +"," + mylon +"("+ markertitle + ")&iwloc=A&hl=en"; 
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress)); 
startActivity(intent); 

但是,这只是打开在本地浏览器的URL。我如何强制它打开地图应用程序?

回答

1

尝试:

String urlAddress = "http://maps.google.com/maps?q="+ mylat +"," + mylon +"("+ markertitle + ")&iwloc=A&hl=en"; 
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress)); 
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); 
startActivity(intent); 
+0

我应该在清单或声明的东西呢?如何?因为它给了我这个错误: '09-03 22:35:30.062:E/AndroidRuntime(4140):android.content.ActivityNotFoundException:无法找到显式活动类{com.google.android.apps.maps/com。 google.android.maps.MapsActivity};你是否在你的AndroidManifest.xml中声明了这个活动?' – user3673449 2014-09-03 20:38:04

+2

这意味着设备没有安装GoogleMaps应用程序,你可以捕获ActivityNotFoundException以避免崩溃。 – 2014-09-03 20:41:27

+0

您确定您的设备已安装谷歌地图吗? @ user3673449 – 2014-09-04 13:30:49

0

试试这个

String urlAddress = "http://maps.google.com/maps?q="+ mylat +"," + mylon +"("+ markertitle + ")&iwloc=A&hl=en"; 
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse(urlAddress)); 
startActivity(intent); 
相关问题