Android:打开地图意图,指示有两个点

mon*_*yag 16 android google-maps

如何用方向打开地图意图?

我知道

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(Locale.US, "geo:%.8f,%.8f", latitude, longitude)));
startActivity(Intent.createChooser(intent, "Select an application"));
Run Code Online (Sandbox Code Playgroud)

此代码适用于一点.但我希望显示所有地图应用程序的对话框,并使用任何应用程序(Google Map,Citymapper,Web浏览器等)打开从A点到B点的路线.

Col*_*ire 30

你试过这个吗?

String uri = "http://maps.google.com/maps?f=d&hl=en&saddr="+latitude1+","+longitude1+"&daddr="+latitude2+","+longitude2;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(Intent.createChooser(intent, "Select an application"));
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,我会用其他应用程序检查它(1-2天),因为“Citymapper”不适合我(崩溃),“Ynadex Maps”(不支持这个api?)也不起作用。 (3认同)

小智 6

尝试这个

Uri uri = Uri.parse("geo:" + latitude1 + "," + longitude1 + "?q=" + Uri.encode(latitude2 + "," + longitude2 + "(" +Label+ ")"));
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)