2010-02-08 113 views

回答

-2
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <title>Google Maps JavaScript API Example</title> 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg&sensor=true_or_false" 
      type="text/javascript"></script> 
    <script type="text/javascript"> 

    function initialize() { 
     if (GBrowserIsCompatible()) { 
     var map = new GMap2(document.getElementById("map_canvas")); 
     map.setCenter(new GLatLng(37.4419, -122.1419), 13); 
     map.setUIToDefault(); 
     } 
    } 

    </script> 
    </head> 
    <body onload="initialize()" onunload="GUnload()"> 
    <div id="map_canvas" style="width: 500px; height: 300px"></div> 
    </body> 
</html> 

的map.setCenter()函數可用於設置縮放級別,即map.setCenter(座標的GLatLng,縮放級別)

+0

這不是用戶問。他需要一種*自動*的方式來做到這一點。 – 2010-03-11 15:27:18

0

你可以要求一定geoposition儘可能高的變焦: https://developers.google.com/maps/documentation/javascript/maxzoom

我已經集成創建地圖後調用。所以,雖然地圖加載同時也請求了最大縮放級別,並將其重置地圖縮放級別,只有當它比地圖的縮放級別較低:

this.map = this.createMap(this.el, this.initPosition); 
var maxZoomService = new google.maps.MaxZoomService(); 
maxZoomService.getMaxZoomAtLatLng(this.initPosition, _.bind(function(response) { 
    if (response.status != google.maps.MaxZoomStatus.OK) { 
     return; 
    } else { 
     console.log("GoogleMapView maxzoomlevel is " + response.zoom); 
     if (response.zoom < this.map.getZoom()) { 
      this.map.setZoom(response.zoom); 
     } 
    } 
}, this)); 
相關問題