当前位置: 动力学知识库 > 问答 > 编程问答 >

google maps api 3 - get current latlng bounds?

问题描述:

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 );
        }
    });
分享给朋友:
您可能感兴趣的文章:
随机阅读: