如何从谷歌地图方向api获得总旅行距离和路线,如优步 [英] How to get total travelled distance and route from google map directions api like uber

查看:301
本文介绍了如何从谷歌地图方向api获得总旅行距离和路线,如优步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Google地图方向API获取总旅行距离和路线,以
显示用户像Uber一样走过的路径。 您可以使用 矩阵/介绍rel =nofollow noreferrer> Google Maps Distance Matrix API ,它为原点和目的地矩阵提供行程距离和时间。它根据Google Maps API计算的开始点和结束点之间建议的路线返回信息,并且包含包含每对的持续时间和距离值的行。

Google Maps Distance Matrix API请求采用以下格式:
https://maps.googleapis.com/maps/api/distancematrix/outputFormat?parameters 其中 outputFormat 可以是以下任一值:
$ b

  • json(推荐) JavaScript对象表示法(JSON);或

  • xml,以XML表示输出。 ://github.com/vastavch/GoogleMapsDistanceMatrixAPI_Demorel =nofollow noreferrer> GitHub的例子。本教程将找到在驾驶模式下行驶的距离和时间,并避免使用Google Maps Distance Matrix API从起点到目的地的收费。



    这里还有一些相关的SO问题:



    >

    希望这有助于!


    How to get total travelled distance and route from google map directions API to show user travelled path like Uber.

    解决方案

    You can use the Google Maps Distance Matrix API that provides travel distance and time for a matrix of origins and destinations. It returns information based on the recommended route between start and end points, as calculated by the Google Maps API, and consists of rows containing duration and distance values for each pair.

    A Google Maps Distance Matrix API request takes the following form: https://maps.googleapis.com/maps/api/distancematrix/outputFormat?parameters where outputFormat may be either of the following values:

    • json (recommended), indicates output in JavaScript Object Notation (JSON); or
    • xml, indicates output as XML.

    Check this example from GitHub. The tutorial finds the distance and time taken to travel in driving mode and by avoiding tolls from origin to destination using Google Maps Distance Matrix API.

    Here also are some related SO questions:

    Hope this helps!

    这篇关于如何从谷歌地图方向api获得总旅行距离和路线,如优步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆