Google地图在给定窗口中选择缩放以适合国家/地区 [英] Google Maps choose zoom to fit country TIGHTLY in given window
问题描述
我刚开始使用Google Maps API。我成功地创建了一个以给定国家为中心的地图。
I am just starting out with the Google Maps API. I have successfully managed to create a map centered on a given country
function create_map (geometry) {
var mapOptions = {
center: geometry.position,
zoom: 6 // unimportant, see fitBounds
};
var map = new google.maps.Map (
document .getElementById ("map-canvas"),
mapOptions);
map.fitBounds (geometry.viewport);
}
function initialize ()
{
new google.maps.Geocoder().geocode (
{'address': 'france'},
function (results, status)
{
if (google.maps.GeocoderStatus.OK == status)
create_map (results [0].geometry);
else
alert ("bad: "+ status);
});
}
google.maps.event.addDomListener (window, 'load', initialize);
这种方式可行,但缩放级别选择空间很大。我希望地图尽可能大,没有舒适的边缘。我怎样才能使API紧密贴合窗口?
This works but the zoom level is chosen with lots of room to spare. I want the map to be as big as possible, with no "comfortable" margin. How can I make the API fit the map tightly to the window?
推荐答案
这是不可能的。缩放地图可能只能设置为整数值,但是您要实现的要求是浮点值。
It's not possible. The zoom of a map may only be set to integer-values, but what you're trying to achieve would require a float-value.
转到 HTTP://gmaps-samples-v3.googlecode .com / svn / trunk / geocoder / v3-geocoder-tool.html#q%3Dfrance
蓝色矩形标记视口,当您增加放大1蓝色矩形将不适合容器。
The blue rectangle marks the viewport, when you increase the zoom by 1 the blue rectangle will not fit into the container.
这篇关于Google地图在给定窗口中选择缩放以适合国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!