使用PHP的Google Maps API查找两个位置之间的距离 [英] Google Maps API with PHP to find distance between two locations

查看:93
本文介绍了使用PHP的Google Maps API查找两个位置之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的项目中,这是一个交付系统,我有一个可用交付驱动程序的列表,它显示在订单页面上。但我需要的是显示每次交付距离客户地址的距离。距离应显示在每个司机的名字旁边。任何人有任何线索我会怎么去做这件事?解决方案

假设你想要驾驶距离而不是直线距离,你可以使用Directions Web服务:
您需要从PHP脚本发出http或https请求,并解析JSON或XML响应。


$ b 文档:
https://developers.google.com/maps/documentation/directions/波士顿,马萨诸塞州马萨诸塞州查尔斯顿和马萨诸塞州列克星敦(马萨诸塞州)的马萨诸塞州康科德马萨诸塞州(JSON)
http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false



马萨诸塞州波士顿至Conc马里兰州马萨诸塞州查尔斯顿和马萨诸塞州列克星敦(马里兰州)通过马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州列克星敦(XML)
,MA& waypoints = Charlestown,MA | Lexington,MA& sensor = falserel =noreferrer> http://maps.googleapis.com/maps/api/directions/xml?origin=Boston,MA&destination=Concord ,MA& waypoints = Charlestown,MA | Lexington,MA& sensor = false



注意有使用限制。


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 each delivery is from the customers address. The distance should be shown next to each driver's name. Anyone have any clues on how I would go about this?

解决方案

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.

这篇关于使用PHP的Google Maps API查找两个位置之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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