谷歌地图缩小限制

时间:2014-02-20 15:50:59

标签: javascript google-maps-api-3

如何在地图上设置缩小限制,它目前让我缩小到我看到多个世界地图的点: zoom out limit too far

JS:

var map;

var all_coor = <?php echo json_encode($addresses); ?>;
var dub = <?php echo json_encode($testadd); ?>;

function initialize() {
var MainLatlng = new google.maps.LatLng(-74.337724,-49.69693);

  var mapOptions = {
    zoom: 7,
    center: new google.maps.LatLng(31.386692,-12.700747)
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

 var markerr = new google.maps.Marker({
      position: MainLatlng ,
      map: map,
      title: 'Main',
      animation: google.maps.Animation.DROP
  });

for (var t = 0, llen = dub.length; t < llen; t++) {

    var marker = new google.maps.Marker({
      position: new google.maps.LatLng(dub[t]['lat'], dub[t]['long']),
      map: map,
      title: dub[t]['title']
    });

}

}


google.maps.event.addDomListener(window, 'load', initialize);

HTML:

<div id="map-container" style="height: 500px;">
<div id="map-canvas" style="width: 100%; height: 100%"></div>
</div>

1.如何设置缩放限制以使地图正确渲染?

1 个答案:

答案 0 :(得分:54)

它被添加到api中,你可以直接在地图对象上设置该选项:

  map.setOptions({ minZoom: 5, maxZoom: 15 });

参考 - https://developers.google.com/maps/documentation/javascript/reference#MapOptions