2017-04-27 74 views
-1

脚本芝加哥:获取变焦城市

var current = new google.maps.LatLng(41.8333925, -88.); 
map.setCenter(current); 

脚本的丹维尔:

var current = new google.maps.LatLng(36.5925975, -79.5510265); 
map.setCenter(current); 

它的工作不错,但我必须使用此setZoom。

所以,如果我使用:

map.setZoom(10); 

这有利于芝加哥,但它丹维尔是太远(12是好的)。

是否有一个类似的函数setZoom,它会给我一个只有给定城市边界的地图?芝加哥和丹维尔只是例子。

+0

http://stackoverflow.com/a/11454897/3575770 – phpnerd

回答

0

我想你可以使用此代码:

var geocoder = new google.maps.Geocoder(); 
    geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
     map.setCenter(results[0].geometry.location); 
     map.fitBounds(results[0].geometry.viewport); 
     } 
    }); 

Source

+0

可惜还是变焦是相同的。 – dimad