Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps v3 zoom end

Tags:

google-maps

I have a problem with google maps v3 zoom_change, as it doesn't solve my need perfectly.

I have 2 unmet requirements:

  • I need to get the bounds and show points that are inside the bounds after the user clicked in zoom control and zoom has been reajusted in the map. The method zoom_change do it before reajusting zoom, and the bounds aren't the ones I need.

  • The method zoom_change is called every time, for example, whenever I execute fitBounds or setZoom. I only need it when when zoomcontrol is clicked or when mousewheel is moved.

Is there a solution available in the v3 API for those issues?

like image 277
David Avatar asked Sep 01 '11 10:09

David


People also ask

What is the maximum zoom level in Google map?

Furthermore, the maximum value of Google Maps Zoom level is 22. Therefore, the defined maximum value must be below or equal to 22, which is the default. The minimum value of Zoom Level is 0 by default, it can be changed by the shortcode as well.

How do I change the zoom level on Google Maps?

Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map for touchscreen devices.

How do you zoom in on Google map 3d?

Hold down the control key on your keyboard, and left click and drag. Use the scroll wheel on your mouse to zoom in and out. (Yes, a mouse with a scroll wheel is a big help here.) This gives you complete 3-D viewing.


2 Answers

Listen for the idle event.

From Google Maps Javascript API V3 Reference:

idle: This event is fired when the map becomes idle after panning or zooming.

like image 126
Justin McConnell Avatar answered Oct 17 '22 02:10

Justin McConnell


The event is called zoom_changed (NOTzoom_change). The event handler of this event is called AFTER the zoom has changed. It is indeed not straightforward to distnguish the zoom change caused by the user from that one caused by the program. A possible solution is to maintain a "global" variable say userZoom which denotes whether the user triggered the zoom.

var userZoom = true; // initial value: be prepared for user action
// Install listener
google.maps.event.addListener(Map.self, 'zoom_changed', function() {
    if (userZoom) {      
        // the user changed zoom: do what should be done
    }
    else {
        // zoom change caused by a program action: ignore
    }
    userZoom = true;  // be prepared for the user zoom action    
});

Before you call any of the program actions that change the zoom, set userZoom = false, e.g.

userZoom = false;
map.setZoom(9);
like image 36
Jiri Kriz Avatar answered Oct 17 '22 01:10

Jiri Kriz