获取视口两侧的纬度和经度 [英] Get latitude and longitude of the viewport's sides

查看:91
本文介绍了获取视口两侧的纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

获取当前的latlng界限?

我正在寻找最好的使用Google maps API获取地图视口的纬度和经度的方法。理想情况下,我希望能够使用地图的上下边界的纬度和边的经度。想法是弄清楚可见地图的区域,并根据地图上当前可见的内容调整页面上的一些相关元素。地图的API中是否有一个处理此功能的函数?

I'm looking for the best way to use the Google maps API to get the latitude and longitude of the map viewport. Ideally I'd like to be able to use the latitude of the map's upper and lower borders and the longitude of the sides. The idea is the figure out the area of the visible map and adjust some related elements on the page based on what's currently visible on the map. Is there a a function in the map's API that handles this?

谢谢,非常感谢任何帮助。

Thanks, any help is much appreciated.

推荐答案

Map.getBounds() 为您提供 当前视口的LatLngBounds 。然后,您可以使用 LatLngBounds.getNorthEast() LatLngBounds.getSouthWest()来获取东北(右上角)和西南(左下角)坐标为 经纬度 。更具体地说:

Map.getBounds() gives you the LatLngBounds of the current viewport. You can then use LatLngBounds.getNorthEast() and LatLngBounds.getSouthWest() to get north-east (top right) and south-west (bottom-left) coordinates as LatLng. More specifically:

var lat0 = map.getBounds().getNorthEast().lat();
var lng0 = map.getBounds().getNorthEast().lng();
var lat1 = map.getBounds().getSouthWest().lat();
var lng1 = map.getBounds().getSouthWest().lng();

这篇关于获取视口两侧的纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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