0
我的問題是fitBounds通常會使對象居中,但太小。我希望它應該將中心地圖放在特定對象上並儘可能地放大它。事實上,縮放級別通常可以高一級。請考慮我的example。正如你所看到的,這個國家可以放大到一個水平,並且仍然是100%可見的。有什麼方法可以克服它嗎?爲什麼谷歌地圖的fitBounds如此不準確?
這裏是我的代碼:
$(document).ready(function(){
var locationBBOX = [["14.149166 49.002914","24.14444 49.002914","24.14444 54.834442","14.149166 54.834442","14.149166 49.002914"]];
var map = new google.maps.Map(
document.getElementById('map-div'), {
center: new google.maps.LatLng(0, 0),
disableDefaultUI: true,
zoom: 1,
mapTypeId: google.maps.MapTypeId.ROADMAP });
var _bounds = new google.maps.LatLngBounds();
for(var k in locationBBOX)
{
var _c1 = locationBBOX[k][0].split(' ');
var _c2 = locationBBOX[k][2].split(' ');
var _bbox = new google.maps.LatLngBounds(new google.maps.LatLng(parseFloat(_c1[1]),parseFloat(_c1[0])),new google.maps.LatLng(parseFloat(_c2[1]),parseFloat(_c2[0])));
_bounds.union(_bbox);
}
map.fitBounds(_bounds);
var ne = _bounds.getNorthEast();
var sw = _bounds.getSouthWest();
var boundingBoxPoints = [
ne, new google.maps.LatLng(ne.lat(), sw.lng()),
sw, new google.maps.LatLng(sw.lat(), ne.lng()), ne
];
var boundingBox = new google.maps.Polyline({
path: boundingBoxPoints,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
boundingBox.setMap(map);
});
謝謝!