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

javascript - Disable "zoom in" function for google maps - Stack Overflow

programmeradmin3浏览0评论

I list my users on the google maps based on their locations. But I dont want it zoom in to a degree where others can see on what street they live. Is there a way to disable "zoom in" feature in the following Google maps codes?

Thanks!

function initialize() {
    var data = <%=Data%>;
    var center = new google.maps.LatLng(48.404840395764175, 2.6845264434814453);
    var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 2,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var markers = [];
    for (var i = 0; i < data.users.length; i++) {
        var location = data.users[i];
        var latLng = new google.maps.LatLng(location.latitude, location.longitude);
        var marker = new google.maps.Marker({ position: latLng });
        markers.push(marker);
    }
    var markerCluster = new MarkerClusterer(map, markers);
}
google.maps.event.addDomListener(window, 'load', initialize);

I list my users on the google maps based on their locations. But I dont want it zoom in to a degree where others can see on what street they live. Is there a way to disable "zoom in" feature in the following Google maps codes?

Thanks!

function initialize() {
    var data = <%=Data%>;
    var center = new google.maps.LatLng(48.404840395764175, 2.6845264434814453);
    var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 2,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var markers = [];
    for (var i = 0; i < data.users.length; i++) {
        var location = data.users[i];
        var latLng = new google.maps.LatLng(location.latitude, location.longitude);
        var marker = new google.maps.Marker({ position: latLng });
        markers.push(marker);
    }
    var markerCluster = new MarkerClusterer(map, markers);
}
google.maps.event.addDomListener(window, 'load', initialize);
Share Improve this question edited May 30, 2012 at 13:14 James Allardice 166k22 gold badges334 silver badges315 bronze badges asked May 30, 2012 at 13:08 EfeEfe 9543 gold badges20 silver badges37 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

You can add minZoom and maxZoom properties to the options object you pass to the Map constructor:

var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 2,
    center: center,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    maxZoom: 10
});

From the docs for maxZoom:

The maximum zoom level which will be displayed on the map. If omitted, or set to null, the maximum zoom from the current map type is used instead.

This can be used to disable scroll when mouse is hovered over map.

scrollwheel: false 
发布评论

评论列表(0)

  1. 暂无评论