我有这个网址
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我们可以得到这个请帮助/指导,
感谢
答案 0 :(得分: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希望有所帮助
答案 1 :(得分:2)
我认为Google API会为您提供帮助。
http://code.google.com/apis/maps/documentation/directions/
此外,我认为本指南会对您有所帮助。
http://briancray.com/2009/06/23/calculate-driving-distance-google-maps-api/