简体   繁体   English

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

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

Well i am working in a location based app and i need to find driving distance between two location on earth at the server end.好吧,我正在一个基于位置的应用程序中工作,我需要在服务器端找到地球上两个位置之间的行驶距离。 i am coding the web service in php.我在 php 中编码 web 服务。

Till now i am able to calculate the aerial distance using the Haversine formula, but now i want to calculate the driving distance.到目前为止,我能够使用 Haversine 公式计算空中距离,但现在我想计算行驶距离。

There can be possible duplicates for this question, but i was not able to find any help to calculate the "Driving distance" between two "coordinates" ie latitude and longitude instead of addresses in PHP这个问题可能有重复,但我无法找到任何帮助来计算两个“坐标”之间的“行驶距离”,即纬度和经度,而不是 PHP 中的地址

This should get you started...这应该让你开始......

$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']);

Use Google Distance Matrix API :-使用谷歌距离矩阵 API :-

The Google Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations. Google 距离矩阵 API 是一项服务,可提供起点和终点矩阵的行驶距离和时间。

Here is the code:-这是代码: -

$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>";

Find out more at Google Distance Matrix APIGoogle 距离矩阵 API中了解更多信息

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

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