我使用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