2015-04-01 38 views
0

我想停止滚动我的谷歌地图。我已经看过其他问题,并且大多数答案都表示将scrollwheel:false设置为您的地图选项,但这种方法无效。有没有人有这个指针?谷歌地图API - 如何停止滚动(JavaScript)

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);

+0

不同于论坛的网站,我们不使用“谢谢”,或“任何帮助表示赞赏”,或签名[so]。请参阅“[应该'嗨','谢谢',标语和致敬从帖子中删除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be - 删除 - 从帖子)。顺便说一句,它是“预先感谢”,而不是“感谢先进”。 – 2015-05-01 04:37:16

回答

1

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

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

对不起,我应该在问题中解释一下。感谢您的帮助,我现在感觉自己像个傻瓜! – Fran 2015-04-01 19:18:13

+0

@FranHaines不要说,每个人都会犯错误! – 2015-04-01 19:22:15