我使用Google API v3中的地理編碼器顯示國家/地區的地圖。我得到了國家推薦的視口,但是當我想將地圖調整到該視口時,它不起作用(請參閱下面的代碼中調用fitBounds函數之前和之後的邊界)。Google地圖api V3中的fitbounds()不適合邊界
我在做什麼錯?
如何將我的地圖的視口設置爲results[0].geometry.viewport
?
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{'address': '{{countrycode}}'},
function(results, status) {
var bounds = new google.maps.LatLngBounds();
bounds = results[0].geometry.viewport;
console.log(bounds); // ((35.173, -12.524), (45.244, 5.098))
console.log(map.getBounds()); // ((34.628, -14.683), (58.283, 27.503))
map.fitBounds(bounds);
console.log(map.getBounds()); // ((25.740, -24.806), (52.442, 17.380))
}
);
謝謝Daniel。 – jul 2010-03-23 11:41:02
我也很難理解如何做到這一點,真棒詳細的解釋! – designermonkey 2011-04-13 09:18:37
非常感謝您的詳細解釋。 boundingBox是一個很好的主意,可以清楚地說明這一點。 – Symmetric 2012-06-05 05:17:15