谷歌地图API-如何停止滚动(JavaScript)

Google Map API - How to Stop Scrolling (JavaScript)

本文关键字:JavaScript 滚动 何停止 API- 谷歌地图      更新时间:2023-09-26

我正试图停止在谷歌地图上滚动。我看过其他问题,大多数答案都说在地图选项中添加滚动条:false,但这并没有奏效。有人对此有什么建议吗?

function initialize() {
  var myLatlng = new google.maps.LatLng(51.843143, -2.643555),
    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 12,
      center: myLatlng
    }),
    infowindow = new google.maps.InfoWindow({
      content: "<b>Paddle the Wye base</b>"
    }),
    marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: "We are here!"
    });
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map, marker);
  });
  infowindow.open(map, marker);
  var accessPoint1 = new google.maps.LatLng(51.840913, -2.638603),
    marker1 = new google.maps.Marker({
      position: accessPoint1,
      map: map,
      title: "Access Point 1"
    });
  map.controls[google.maps.ControlPosition.TOP_LEFT].push($("#findButton")[0]);
  function successCallback(position) {
    var latlng = new google.maps.LatLng(position.coords.latitude,
        position.coords.longitude),
      myOptions = {
        zoom: 3,
        center: latlng,
        mapTypeControl: false,
        scrollwheel: false,
        navigationControlOptions: {
          style: google.maps.NavigationControlStyle.SMALL
        },
        mapTypeId: google.maps.MapTypeId.ROADMAP
      },
      bounds = new google.maps.LatLngBounds(latlng);
    bounds.extend(marker.getPosition());
    map.setOptions(myOptions);
    map.fitBounds(bounds);
    new google.maps.Marker({
      position: latlng,
      map: map,
      title: "You are here!",
      icon: 'http://maps.gstatic.com/mapfiles/markers2/boost-marker-mapview.png'
    });
  }
  function errorCallback() {
    alert("I'm afraid your browser does not support geolocation.");
  }
  function findMe() {
    $(this).hide();
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {
        timeout: 10000
      });
    } else {
      alert("I'm afraid your browser does not support geolocation.");
    }
  }
  $("#findButton").click(findMe);
}
google.maps.event.addDomListener(window, 'load', initialize);

我不能完全理解你的代码,但你必须在这里添加它:

var myLatlng = new google.maps.LatLng(51.843143, -2.643555),
    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 12,
      center: myLatlng,
-->      scrollwheel: false
    }),