最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get the MapOptions object from a map with Google Maps API v3 - Stack Overflow

programmeradmin8浏览0评论

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.

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.

Share Improve this question edited Mar 21, 2022 at 0:25 user2314737 29.5k20 gold badges107 silver badges123 bronze badges asked Jul 30, 2010 at 8:34 Laurenţiu LozanLaurenţiu Lozan 1031 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You can also access options using the get method on the map as an 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./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>
...

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

  • getZoom()
  • getMapTypeId()
  • getCenter()
  • etc..
发布评论

评论列表(0)

  1. 暂无评论