android google.navigation intent返回旅行时间

时间:2014-02-02 10:32:51

标签: android android-intent navigation

要导航我使用:

            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q="+url));
        mContext.startActivity(i);  

谷歌导航是否有可能返回旅行时间?

1 个答案:

答案 0 :(得分:1)

您可以使用Google Directions API并获得JSON,其中包含持续时间,距离等信息。

duration: {
text: "5 hours 22 mins",
value: 19325
},

请求(从多伦多到蒙特利尔的示例路线)

http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false

完整输出:

{
    routes: [
        {
            bounds: {
                northeast: {
                    lat: 45.5110114,
                    lng: -73.5535278
                },
                southwest: {
                    lat: 43.6533103,
                    lng: -79.3837332
                }
            },
            copyrights: "Map data ©2014 Google",
            legs: [
                {
                    distance: {
                        text: "542 km",
                        value: 542389
                    },
                    duration: {
                        text: "5 hours 22 mins",
                        value: 19325
                    },
                    end_address: "Montreal, QC, Canada",
                    end_location: {
                        lat: 45.5085712,
                        lng: -73.5537674
                    },
                    start_address: "Toronto, ON, Canada",
                    start_location: {
                        lat: 43.6533103,
                        lng: -79.3827675
                    },
                    steps: [

                    ],
                    via_waypoint: [

                    ]
                }
            ],
            overview_polyline: {
                points: ""
            },
            summary: "ON-401 E",
            warnings: [

            ],
            waypoint_order: [

            ]
        }
    ],
    status: "OK"
}