0

我正在使用DistanceWidget插件。這是我的代碼:錯誤標記出現在Google地圖上的圓圈外

var distanceWidget = new DistanceWidget(map); 
displayMarker(distanceWidget, markers); 

google.maps.event.addListener(distanceWidget, 'distance_changed', function() { 
    displayMarker(distanceWidget, markers); 
}); 

google.maps.event.addListener(distanceWidget, 'position_changed', function() { 
    displayMarker(distanceWidget, markers); 
}); 

而這個功能顯示/隱藏標記

function displayMarker(circle, markers) { 
    var bounds = circle.get('bounds'); 
    for (var i=0; i<markers.length; i++) { 
     if(bounds.contains(markers[i].getPosition())) { 
      markers[i].setVisible(true); 
     } else { 
      markers[i].setVisible(false); 
     } 
    } 
} 

這是我的錯誤 Error

+0

圓的邊界一個陣列是廣場。 – geocodezip

+0

相關問題:[Google maps JS API v3:使用containsLocation()獲取標記不起作用 - 爲什麼?](http://stackoverflow.com/questions/28254090/google-maps-js-api-v3-獲得標誌物,內接圓與 - containslocation-犯規,WOR) – geocodezip

回答

0

u需要先檢查度過一個特別的標記位於圓或不 如果是,那麼它會自動出現在圓圈中,否則您需要將該標記放置在該圓圈中。

其他的解決方案是:U需要使用的LatLngBounds方法是這樣的

 var bounds = new google.maps.LatLngBounds(); 
     for (var i = 0, LtLgLen = arrZom.length; i < LtLgLen; i++) { 
      bounds.extend(arrZom[i]); 
     } 
     map.fitBounds(bounds); 

arrZom是包含所有標記的緯度和LNG(google.maps.LatLng)

相關問題