ActivityNotFound - 使用Intent启动Google Map

时间:2013-12-12 05:38:11

标签: android google-maps android-intent geolocation gps

我正在编写一个程序,用户可以在Android中启动谷歌地图,启动谷歌地图,我正在使用意图,但遇到了问题。

错误说:

 android.app.Activity.startActivityForResult(Activity.java:3395)

logcat的: -

12-13 15:00:15.620: E/AndroidRuntime(5819): FATAL EXCEPTION: main
12-13 15:00:15.620: E/AndroidRuntime(5819): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=?q=pizza+hut48.89364,2.33739&z=16 }
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.app.Activity.startActivityForResult(Activity.java:3434)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.app.Activity.startActivityForResult(Activity.java:3395)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.app.Activity.startActivity(Activity.java:3605)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.app.Activity.startActivity(Activity.java:3573)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at com.example.gpstracking.AndroidGPSTrackingActivity$1.onClick(AndroidGPSTrackingActivity.java:41)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.view.View.performClick(View.java:4223)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.view.View$PerformClick.run(View.java:17275)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.os.Handler.handleCallback(Handler.java:615)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.os.Looper.loop(Looper.java:137)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at android.app.ActivityThread.main(ActivityThread.java:4921)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at java.lang.reflect.Method.invokeNative(Native Method)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at java.lang.reflect.Method.invoke(Method.java:511)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
12-13 15:00:15.620: E/AndroidRuntime(5819):     at dalvik.system.NativeStart.main(Native Method)
12-13 15:00:23.730: I/Process(5819): Sending signal. PID: 5819 SIG: 9

代码启动Google地图,使用Intent显示附近的PizzaHut

 double latitude = gps.getLatitude();
 double longitude = gps.getLongitude();
 String uriBegin = latitude + "," + longitude;
 String uriString = "?q=pizza+hut" + uriBegin + "&z=16";
 Uri uri = Uri.parse(uriString);
 Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
 startActivity(intent);

2 个答案:

答案 0 :(得分:1)

试试这个网址 相应地更改查询和位置参数 这里q是指定你的查询ll是你的纬度和经度,z是缩放级别

https://maps.google.com/?q=pizza+hut&ll=-33.867701,151.208471&z=12

在您的应用中添加这段代码

Uri uri = Uri.parse("https://maps.google.com/?q=pizza+hut&ll=-33.867701,151.208471&z=12");
     Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
     intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
     startActivity(intent);

答案 1 :(得分:1)

使用用户的当前位置显示附近的必胜客餐厅,并启动 Google地图,无需对话

如果你想摆脱对话框,你可以给意图一个关于你想要使用哪个包的提示。在 startActivity() 之前添加:

intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");

最后,您的代码 应该如下所示

double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
String uriBegin = latitude + "," + longitude;
String uriString = "https://maps.google.com/?q=pizza+hut&ll=" + uriBegin + "&z=12";
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
intent.setClassName("com.google.android.apps.maps",   "com.google.android.maps.MapsActivity");
startActivity(intent);