2011-10-15 42 views
1

我在我的項目中使用Google map v3 direction api從google map v3 direction api的結果中獲取經度和緯度?

我給出的城市名稱爲start pointend point以獲得距離和距離的距離。

我有另一個要求獲取城市名稱的起點的經度和緯度。

我可以從方向api得到它嗎?我用這個方向api來獲取方向api的結果中的距離和時間?

如果我們能從方向api的結果中獲得經緯度,那麼請給予適當的回答以幫助我。

在此先感謝。

回答

0

快速查看responses section of the directions API documentation,看起來您可以像獲取距離和時間一樣獲取start_location - > lat和start_location - > lng。

我想這將是:

routes.legs[0].start_location.lat 
routes.legs[0].start_location.lng 
+0

感謝您的回答!但我沒有得到確切的答案... – sikender

+0

從您的代碼輸出是: - function(){ return this [a]; } – sikender

+0

您如何將您使用的代碼放在問題中獲得距離和時間?那麼正確回答會更容易。 – HenningJ

0

響應不包含緯度/經度的字符串。你必須使用函數來獲取它。

使用jquery這適合我。

$.each(result.routes[0].legs, function(index, route) { 
alert(route.start_location.lat()); 
}); 

這會提醒您要求的每一段旅程的每個起始緯度。

相關問題