Created
October 4, 2011 08:54
-
-
Save mbeaty/1261182 to your computer and use it in GitHub Desktop.
Google Maps fit bounds on marker and re-set zoom level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// addMarker() is just a method that creates a marker and adds it to a marker array; it returns | |
// the marker it just added. | |
var bounds = new google.maps.LatLngBounds(); | |
var markerPos = addMarker(point.latitude, point.longitude).getPosition() | |
bounds.extend(markerPos); | |
map.fitBounds(bounds); | |
map.setZoom(14); |
Is there a way to set the zoom level to each markers.If yes how can i set the zoom level to each markers?
Shouldnt work always because its done asynchronously..
Its better to re-set the zoom like that:
map.fitBounds(this.map.bounds); zoomChangeBoundsListener = google.maps.event.addListenerOnce(map, 'bounds_changed', function(event) { if ( this.getZoom() ){ // or set a minimum this.setZoom(16); // set zoom here } }); setTimeout(function(){google.maps.event.removeListener(zoomChangeBoundsListener)}, 2000);
Thanks u so much, i have solved this bug about zoom out map after load marker in 2hours. Thanks u !!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldnt work always because its done asynchronously..
Its better to re-set the zoom like that: