How to get the MapOptions object from a map with Google Maps API v3

In Google Maps api v2 you could get parameters such as the map type, zoom etc directly from the map object. In version 3 you have the setOptions method to set some parameters, but there is no getOptions() or options to retrieve them.


You can access those properties via methods on the Map class:

  • getZoom()
  • getMapTypeId()
  • getCenter()
  • etc..

  • 您还可以使用地图上的get方法作为MVCObject访问选项,如本例所示

    // create map
    var myLatlng = new google.maps.LatLng(-33, 151);
    var myOptions = {
      center: myLatlng,
      zoom: 5
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    map.setOptions({
      streetViewControl: false,
      zoom: 6,
      zoomControl: false,
      }
    );
    
    document.getElementById("center").value = map.get('center');
    document.getElementById("streetViewControl").value = map.get('streetViewControl');
    document.getElementById("zoom").value = map.get('zoom');
    document.getElementById("zoomControl").value = map.get('zoomControl');
    #map_canvas {
      width: 50%;
      height: 200px;
      float: left;
    }
    
    input {
      width: 90px;
      }
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <div id="map_canvas"></div>
    
    <input type="text" id="center" /> center<br>
    <input type="text" id="streetViewControl" /> streetViewControl<br>
    <input type="text" id="zoom" /> zoom<br>
    <input type="text" id="zoomControl" /> zoomControl<br>
    ...
    链接地址: http://www.djcxy.com/p/2300.html

    上一篇: 使用Visual Studio 2010部署Web应用程序是否有更好的方法?

    下一篇: 如何使用Google Maps API v3从地图中获取MapOptions对象