Get latitude and longitude of the viewport's sides

前端 未结 2 411
不知归路
不知归路 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:04

    Use method getBounds of the Map class.

    0 讨论(0)
  • 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();
    
    0 讨论(0)
提交回复
热议问题