首页 > 解决方案 > 如何使用应用程序中的意图打开谷歌地图并自动导航以显示两点之间的路线和距离

问题描述

我已经尝试过这种方式,但它不会自动导航到这一点。

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);

标签: androidgoogle-mapsdictionary

解决方案


试试这个功能

 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);
    }

传递目的地位置的经纬度。


推荐阅读