首页 > 解决方案 > 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?

标签: androidgoogle-mapsandroid-intentyandex-mapsandroid-intent-chooser

解决方案


推荐阅读