Get latitude and longitude of the viewport's sides

前端 未结 2 429
不知归路
不知归路 2020-12-28 16:45

Possible Duplicate:
get current latlng bounds?

I\'m looking for the best way to use the Google maps API to ge

2条回答
  •  [愿得一人]
    2020-12-28 17:06

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

提交回复
热议问题