如何在Google地图上禁止在地图中移动?

时间:2015-10-18 00:11:39

标签: google-maps google-maps-api-3

有没有办法禁止在地图上移动?

 var map = new google.maps.Map(document.getElementById('map-canvas'), {
    center:{
        lat: lat,
        lng: lng
    },
    zoom: 15
});

我想让我的地图定位在纬度和经度上,缩放是特定的,地图要保持静态(就像图片一样),所以除了地图中提供的内容之外你什么都看不到

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

禁用拖动,缩放,默认用户界面等。

var map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: {
        lat: 42,
        lng: -72
    },
    zoom: 15,
    draggable: false,
    zoomControl: false,
    streetViewControl: false,
    mapTypeControl: false,
    disableDoubleClickZoom: true,
    scrollwheel: false,
    disableDefaultUI: true
});

proof of concept fiddle

代码段



function initialize() {
  var map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: {
      lat: 42,
      lng: -72
    },
    zoom: 15,
    draggable: false,
    zoomControl: false,
    streetViewControl: false,
    mapTypeControl: false,
    disableDoubleClickZoom: true,
    scrollwheel: false,
    disableDefaultUI: true

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

html,
body,
#map-canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}

<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map-canvas"></div>
&#13;
&#13;
&#13;