2017-04-27 72 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