不设置一个位置如何开启 google 导航?当我试着实现这个功能时,它实际上是运行 Google Navigation ,但是只重启Activity。事实上我想实现当点击一个主屏幕的 Navigation,就能运行。
我使用下面的intent:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setClassName("com.google.android.apps.maps", "com.google.android.maps.driveabout.app.NavigationActivity");
getContext().startActivity(i);
如果您希望点击主屏幕上的导航按钮时运行 Google 导航,则可以使用如下 intent 来启动 Google Maps 应用程序并设置目的地:
String url = "http://maps.google.com/maps?daddr=" + destLat + "," + destLng;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setPackage("com.google.android.apps.maps");
getContext().startActivity(intent);
其中,destLat 和 destLng 是目的地的经纬度坐标。
如果您想要直接启动导航而不是在地图上显示目的地,可以使用下面的 intent:
String url = "google.navigation:q=" + destLat + "," + destLng;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
getContext().startActivity(intent);
请注意,这种方法需要用户已经安装了 Google Maps 应用程序。