我正在使用GWT2.5和GoogleMap Api3。我有兩個場景: 1.我有地圖的中心latlng和幾個標記。 2.任何縣和少數標記。如何在GWT中爲GoogleMap Api3設置適當的縮放級別
因此,地圖應適當放大以適應標記。
有沒有辦法自動檢測縮放級別?
我正在使用GWT2.5和GoogleMap Api3。我有兩個場景: 1.我有地圖的中心latlng和幾個標記。 2.任何縣和少數標記。如何在GWT中爲GoogleMap Api3設置適當的縮放級別
因此,地圖應適當放大以適應標記。
有沒有辦法自動檢測縮放級別?
谷歌地圖沒有一個「fitAllMarkers
」函數/方法,但你應該能夠合理地實現這一目標只需使用fitBounds
方法。
我不測試下面的代碼,但這樣的事情應該工作:
// A list of all your markers.
List<Marker> markers;
// Get the current bounds of your map.
LatLngBounds latLngBounds = googleMap.getBounds();
for(Marker marker : markers) {
// Extend the bounds of your map to fit the position (LatLng) of each marker.
latLngBounds.extend(marker.getPosition());
}
// This may not be needed - test it.
// Tell the map to zoom to fit the bounds that you defined for your markers.
googleMap.fitBounds(latLngBounds);
它的工作...謝謝... – Sree