2013-05-19 46 views
-1

我引用谷歌地圖的一些位置(通過加載使用AJAX JSON數據),然後我這些點存儲在數組中,然後我在一個數組鏈接一些標記彼此並存儲折線好。獲取經緯度給出一個點

現在我試圖過濾一些標記(給定它們的名稱),我從前面的列表中檢索相應的標記(或點),並且我在所有多段線上執行循環以獲得具有後一點的那些作爲開始或結束。 的問題是,我從折線僅僅是開始的座標,並使用此功能polyline.getPath().getAt(indiceLoop);末拿到了,我需要與此相比,該點的座標。

那麼,有沒有一種方式來獲得座標經緯度給出一個已經創建的點?

非常感謝!

+1

你的意思是讓給它([google.maps.Marker.getPosition]參​​考(標記的座標https://developers.google.com/maps/documentation/JavaScript的/參照#標記))?如何保存「已創建的點」?而我創造的標誌,並將其插入到地圖(在每個循環) 我會嘗試你的建議,並早在一分鐘 – geocodezip

+0

點被保存到數組:) – Anas

+0

實際功能:polyline.getPath() .getAt(indiceLoop);正在返回像這樣(5.60518980026245,-0.16678600013256073) 而marker.getPosition()返回一個對象! 如何檢查點是否代表折線的開始或結束? – Anas

回答

1

假設一個google.maps.Marker( 「標記」)和google.maps.Polyline( 「折線」)。未經測試。

if (google.maps.geometry.spherical.computeDistanceBetween(marker.getPosition(),polyline.getPath().getAt(0)) < 0.1) { 
    // marker is at start of polyline 
    alert("marker at start"); 
} else if (google.maps.geometry.spherical.computeDistanceBetween(marker.getPosition(),polyline.getPath().getAt(polyline.getPath().getLength()-1)) < 0.1) { 
    // marker is at end of polyline 
    alert("marker at end"); 
} 
+0

我投了你的答案,並接受它,因爲我最初需要的是獲得一個點的座標,並且你建議getPosition()函數 – Anas

0

其實,我結束了使用marker.getPosition()。等於(line.getpath()。getAt())和同爲行結束它工作得很好!

感謝您的建議:)