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

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

+7
google-maps google-maps-api-3
source share
2 answers

You can access these properties using the methods of the Map class:

+1
source share

You can also access the parameters using the get method on the map as MVCObject , as shown in this example

 // 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> ... 
+2
source share

All Articles