这两天被Google map的getBounds搞得郁闷,在初始化方法map或者onload的时候调用map.getBounds() 总是出问题,要么map==null 要么 getBounds 返回 undefined。
按照 Google Maps API V3 Reference 的如下说明调用也不行
getBounds():Returns the lat/lng bounds of the current viewport. If the map is not yet initialized (i.e. the mapType is still null), or center and zoom have not been set then the result is null.
最后发现这种方式可行或者getBounds只要在setTimeout 第一个参数方法里面被包含都莫问题:
setTimeout ('map.getBounds()',0)
本文介绍了在使用Google Maps API V3时遇到的getBounds()方法的问题及解决方案。作者发现,在地图初始化完成之前调用此方法会返回null或undefined。通过将getBounds()方法放入setTimeout函数中,即使延时时间为0,也能成功获取地图边界。
1043

被折叠的 条评论
为什么被折叠?



