使用PHP的Google Maps API查找两个位置之间的距离

编程入门 行业动态 更新时间:2024-10-21 09:47:01
本文介绍了使用PHP的Google Maps API查找两个位置之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

$ b 文档: developers.google/maps/documentation/directions/

马萨诸塞州波士顿至Conc马里兰州马萨诸塞州查尔斯顿和马萨诸塞州列克星敦(马里兰州)通过马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州马里兰州列克星敦(XML) ,MA& waypoints = Charlestown,MA | Lexington,MA& sensor = falserel =noreferrer> maps.googleapis/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: developers.google/maps/documentation/directions/

For example: Boston,MA to Concord,MA via Charlestown,MA and Lexington,MA (JSON) maps.googleapis/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) maps.googleapis/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查找两个位置之间的距离

本文发布于:2023-11-12 20:23:14,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:距离   位置   两个   Google   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!