Slowly zoom google map on marker double click
Add marker then double click event for the marker
var marker = new google.maps.Marker({
position: location,
map: map,
title: sname
});
google.maps.event.addListener(marker, 'dblclick', function (event) {
// map = marker.getMap();
// map.setCenter(overlay.getPosition()); // set map center to marker position
smoothZoom(map, 12, map.getZoom()); // call smoothZoom, parameters map, final zoomLevel, and starting zoom level
map.setCenter(this.position)//new google.maps.LatLng(latitude, longitude));
});
Then Set Zoom level of map with Timer . here below is function
function smoothZoom(map, max, cnt) {
if (cnt >= max) {
return;
}
else {
z = google.maps.event.addListener(map, 'zoom_changed', function (event) {
google.maps.event.removeListener(z);
smoothZoom(map, max, cnt + 1);
});
setTimeout(function () { map.setZoom(cnt) }, 80); // 80ms is what I found to work well on my system -- it might not work well on all systems
}
}
var marker = new google.maps.Marker({
position: location,
map: map,
title: sname
});
google.maps.event.addListener(marker, 'dblclick', function (event) {
// map = marker.getMap();
// map.setCenter(overlay.getPosition()); // set map center to marker position
smoothZoom(map, 12, map.getZoom()); // call smoothZoom, parameters map, final zoomLevel, and starting zoom level
map.setCenter(this.position)//new google.maps.LatLng(latitude, longitude));
});
Then Set Zoom level of map with Timer . here below is function
function smoothZoom(map, max, cnt) {
if (cnt >= max) {
return;
}
else {
z = google.maps.event.addListener(map, 'zoom_changed', function (event) {
google.maps.event.removeListener(z);
smoothZoom(map, max, cnt + 1);
});
setTimeout(function () { map.setZoom(cnt) }, 80); // 80ms is what I found to work well on my system -- it might not work well on all systems
}
}
Comments
Post a Comment