2013-01-19 33 views
0

我想實現捕捉到標記功能,同時拖動另一個標記。谷歌地圖LatLngBounds包含函數總是返回true

我有檢查,如果兩個標記是「關閉」的功能:現在

function arePointsNear(point1, point2) { 
    var sw = new google.maps.LatLng(point2.lat() - 0.005, point2.lng() - 0.005); 
    var ne = new google.maps.LatLng(point2.lat() + 0.005, point2.lng() + 0.005); 
    var bounds = new google.maps.LatLngBounds(sw, ne); 
    return bounds.contains(point1); 
}; 

,在標記上的拖動事件(從here得到它),我這樣做:

for (var index in allMarkers) { 
    if(allMarkers[index] == marker) { 
     continue; 
    } 

    var point1 = allMarkers[index].position; 
    var point2 = marker.position; 

    // This always returns true 
    var isClose = arePointsNear(point1, point2); 
} 

我做錯了什麼?

回答

0

該算法正在工作..問題出在我的代碼中。我正在檢查相同標記的位置,而不是兩個標記。