2012-02-15 51 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