android - Android 在任何地图应用程序中自动显示从我的位置到给定位置的路线
问题描述
我想显示一个选择器对话框,用户将在他们的设备中选择任何地图应用程序。选择后,应用程序将自动查找设备位置并显示到给定位置的路线(如纬度和经度)。
对于谷歌地图,这段代码在不显示选择器对话框的情况下满足了我的需求,
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?f=d&daddr=" + location));
intent.setComponent(new ComponentName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
startActivity(intent);
但对于 Yandex,我只能在如下地图上显示给定位置,
Intent intent;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + location+ "?q=" + latAndLong));
startActivity(Intent.createChooser(intent, "Select an app"));
有什么方法可以为所有地图应用程序或仅适用于 Google Maps 和 Yandex?
解决方案
推荐阅读
- html - CSS 我可以保护 div 免受来自其他 div 的盒子阴影的影响吗?
- android - 我应该在哪里放置 Maven 设置?
- javascript - ReactJS:未定义不是 Safari 中的对象
- java - 来自外部文件的 Spring Boot 加载配置文件
- r - 在ggplot的图例中添加确切的小数位数
- java - Jetty 不会移除已关闭的套接字 -> 具有相同端口的连接失败
- laravel - 登录laravel 8后未显示愿望清单的产品
- java - 如何防止 ScheduledExecutorService 多次运行
- excel - 格式化评论范围中的特定单元格以适合固定框并使用 VBA 删除空白单元格
- javascript - 当第一个元素的 aria-hidden 处于活动状态时,有条件地渲染第二个元素