Google Maps API with PHP to find distance between two locations

前端 未结 3 1533
礼貌的吻别
礼貌的吻别 2021-01-07 05:23

On my current project, which is a delivery system, I have a list of available delivery drivers, which is shown on an orders page. But what I need is to show the distance eac

3条回答
  •  自闭症患者
    2021-01-07 05:58

    Assuming that you want driving distance and not straight line distance, you can use the Directions web service: You need to make an http or https request from your PHP script and the parse the JSON or XML response.

    Documentation: https://developers.google.com/maps/documentation/directions/

    For example: Boston,MA to Concord,MA via Charlestown,MA and Lexington,MA (JSON) http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false

    Boston,MA to Concord,MA via Charlestown,MA and Lexington,MA (XML) http://maps.googleapis.com/maps/api/directions/xml?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false

    Note that there are usage limits.

提交回复
热议问题