Cheerio
Cheerio

Reputation: 1240

Google Maps: set zoom in options

Im using Google Maps, I added 2 markers.

Online Demo:
http://jsfiddle.net/VnwFT/1/


I just need to set a zoom, I tried in mapOpts and in fitBounds as well:

zoom 
minzoom
maxzoom

e.x:

var mapOpts = {
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    scaleControl: true,
    scrollwheel: false,
        zoom: 16
}

and it doesn't work.

How Could I set a zoom?

Upvotes: 0

Views: 364

Answers (1)

red_alert
red_alert

Reputation: 1728

See what I've done here:

http://jsfiddle.net/VnwFT/27/

First you need to define the center of the map when you initialize it:

var mapOpts = {
    center: new google.maps.LatLng(45.764043,4.835659),
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    scaleControl: true,
    scrollwheel: false,
    zoom: 16
}

Then if you don't need the fitBounds function (the center of the map is already defined on initialize), you could comment it.

Then in the marker click listener you could edit the code to zoom the map on marker click:

google.maps.event.addListener(pushPin, "click", function () {
    infoWindow.setOptions(options);
    infoWindow.open(map, pushPin);
    if (this.sidebarButton) this.sidebarButton.button.focus();
    map.setZoom(16);
});

Upvotes: 1

Related Questions