获得当前的latlng边界? [英] get current latlng bounds?

查看:119
本文介绍了获得当前的latlng边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我如何获得当前经纬度范围,以便我可以map.fitBounds?

解决方案

以下是在bounds_changed事件中捕获当前地图边界的代码

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

然后,您可以使用此代码返回地图绑定

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


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 );
        }
    });

这篇关于获得当前的latlng边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆