我想在单击信息窗口时显示导航方向。
我尝试了一些代码,它显示了预览按钮,但没有显示导航按钮。
我得到的如下图所示:
但是,我想要这样的:
这是我的代码:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?" +
"saddr="+ gps.latitude + "," + gps.longitude + "&daddr=" + marker.getPosition().latitude + "," +
marker.getPosition().longitude+ "&sensor=false&units=metric&mode=driving"));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
最佳答案
您可以关注此documentation了解如何启动 Google map 导航,并提供前往指定地址或坐标的路线导航。
以下是一个 Intent 示例,请求前往澳大利亚悉尼的塔龙加动物园 (Taronga Zoo) 的路线导航:
Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
检查这些相关的 SO 线程:
关于java - 如何在android中的谷歌地图中获取方向导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40341387/