问题描述:

I want to save the current position where to user is watching and restore back after some clicks.

How do I get the current lat longitude bounds so that I could map.fitBounds on it?

网友答案:

Here's the code to capture the current map bounds, on the "bounds_changed" event

google.maps.event.addListener(map, 'bounds_changed', function() {
        try {
            if( initialBounds == null ) {
                initialBounds = map.getBounds(); 
            }
        } catch( err ) {
            alert( err );
        }
    });

Then, you can return the map the bound using this code

google.maps.event.addDomListener(controlUI, 'click', function() {
        // map.setCenter(home)
        if( initialBounds != null ) {
            map.fitBounds( initialBounds );
        }
    });
相关阅读:
Top