繁体   English   中英

在 php 中计算地球上两个坐标之间的行驶距离

[英]to calculate driving distance between two coordinates on earth in php

好吧,我正在一个基于位置的应用程序中工作,我需要在服务器端找到地球上两个位置之间的行驶距离。 我在 php 中编码 web 服务。

到目前为止,我能够使用 Haversine 公式计算空中距离,但现在我想计算行驶距离。

这个问题可能有重复,但我无法找到任何帮助来计算两个“坐标”之间的“行驶距离”,即纬度和经度,而不是 PHP 中的地址

这应该让你开始......

$json = file_get_contents('http://maps.google.com/maps/nav?q=from:Buderim,Australia%20to:Brisbane,Australia');

$details = json_decode($json, TRUE);

var_dump($details['Directions']['Distance']['meters']);

使用谷歌距离矩阵 API :-

Google 距离矩阵 API 是一项服务,可提供起点和终点矩阵的行驶距离和时间。

这是代码: -

$q = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=Seattle&destinations=San+Francisco&mode=driving&sensor=false";

$json = file_get_contents($q);

$details = json_decode($json, TRUE);

echo "<pre>"; print_r($details); echo "</pre>";

Google 距离矩阵 API中了解更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM