2009-11-25 44 views
1

對於我的應用程序,我需要一臺服務器來計算行車路線。使用PHP計算駕車路線?

Google Maps API是專爲客戶端使用,使用Javascript和Flash API。有什麼方法可以運行他們的API的服務器端?

+0

嗨, 是否必須是Google地圖,或者您可以使用Bing地圖嗎?如果是後者,您可以檢查Bing Maps SDK(http://www.microsoft.com/maps/developers/),因爲它提供了SOAP Web服務,我認爲這可以從服務器調用。 – keyboardP 2009-11-25 23:13:43

+0

[Google Maps HTTP API for driving and walking directions]的可能重複(http://stackoverflow.com/questions/2041601/google-maps-http-api-for-driving-and-walking-directions) – miguev 2016-07-07 10:21:48

回答

7

我所知,這不是正式的和谷歌不支持它,但它的工作原理:

$url = str_replace(' ', '%20', "http://maps.google.com/maps/nav?client=yourclient&output=json&q=from: ".$lat1.",".$lon1." to: ".$lat2.",".$lon2); 

$result = file_get_contents($url); 
$data = json_decode(utf8_encode($result), true); 

而且你必須在$ data數組的方向。

+1

我忘了說編輯客戶端以滿足您的需求或用api鍵替換它 – dfilkovi 2009-11-25 23:29:36

+0

該URL從來不是支持的API,只是Google Maps站點的一部分。正確的方法是使用Directions API(在發佈此答案時不可用):https://developers.google.com/maps/documentation/directions/intro – miguev 2016-07-07 10:18:32