android - 如何使用应用程序中的意图打开谷歌地图并自动导航以显示两点之间的路线和距离
问题描述
我已经尝试过这种方式,但它不会自动导航到这一点。
String uri = "http://maps.google.com/maps?saddr="+"22.541035,88.356366"+"&daddr="+"22.541251,88.347414";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
解决方案
试试这个功能
public static void showRouteOnMap(Context mContext, String lat, String lng) {
Uri gmmIntentUri = Uri.parse("google.navigation:q=" + lat + "," + lng);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
mContext.startActivity(mapIntent);
}
传递目的地位置的经纬度。
推荐阅读
- javascript - 尝试在准备好的文档中生成随机背景颜色
- android - 如何在 Google Play 上更改 apk 的签名
- nativescript - Nativescript 4.0 新框架能否使用比 Tabview 或 Sidedrawer 更多的元素?
- html - 具有不同页面宽度的div位置
- maven - 如何在外部设置 Teamcity sonarqube 插件模块列表?
- java - 使用 bcrypt 加密时如何避免在数据库中更新我的密码?
- python - 保存后Openpyxl崩溃带有表格的excel文件
- mongodb - Bson接口有一些问题
- python - 如何在 python 中打印 100 个随机数的“set”并将它们添加到空 set()
- android - 未在不同活动中检索到 SharedPreference 值