2012-02-15 82 views
-4

我有这个URL如何使用卷曲获取距离?

http://www.worldatlas.com/travelaids/driving_distance.htm 

当我把

From city: 
Hollywood, FL, United States 
to city: 
Washington Avenue, Miami Beach, FL, United States 

我得到的18.33mi/29.51km

我需要一个PHP脚本的距离将发送该URL这上述两个地址,并在返回我将获得上述距离。 听说通过使用curl我们可以得到这样的请帮助/指南,

感谢

回答

2

我认为谷歌API将帮助你在这。

http://code.google.com/apis/maps/documentation/directions/

而且我觉得这个指南将帮助你一点。

http://briancray.com/2009/06/23/calculate-driving-distance-google-maps-api/

+0

使用谷歌地图API的受到的每天2500个路线请求查询的限制。 – user1133643 2012-02-15 05:43:22

+2

如果您每天获得2,500多个用户搜索,意味着您的网站非常受欢迎,并且可能有利可图。所以在这种情况下,你可以得到一个商业版本。 http://code.google.com/apis/maps/documentation/premier/ 如果您尝试使用worldatlas网站执行此操作,则必须经常关注它们。因为如果他们修改了搜索条件,您的网站也需要更改。如果他们发现你的服务器IP每天产生超过2500个请求到他们的服务器有可能被阻止.. – 2012-02-15 05:49:41

+0

非常正确,所以我认为必须去4高级包.....谢谢4这个帮助:) – user1133643 2012-02-15 11:21:05

4

像这样的东西应该工作:

 

$origin = urlencode("Hollywood, FL"); 
$destination = urlencode("Washington Avenue, Miami Beach, FL"); 
$url = "http://maps.googleapis.com/maps/api/directions/json?origin=$origin&destination=$destination&sensor=false"; 
// create curl resource 
$ch = curl_init(); 
// set url 
curl_setopt($ch, CURLOPT_URL, $url);

//return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string $output = curl_exec($ch);

// close curl resource to free up system resources curl_close($ch);
$arr = json_decode($output, TRUE); echo ""; print_r($arr); //get distance from this array

编号:Google Maps Directions希望它可以帮助

+0

Google Directions API的使用受限于每天2,500个指示请求的查询限制。 – user1133643 2012-02-15 05:46:21

+3

@ user1133643 - 你有什么意思? – 2012-02-15 06:24:13