Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
41
rated 0 times [  44] [ 3]  / answers: 1 / hits: 28796  / 12 Years ago, fri, january 11, 2013, 12:00:00

Possible Duplicate:

get current latlng bounds?






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.


More From » google-maps

 Answers
5

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

[#80927] Thursday, January 10, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diamondlauryna

Total Points: 386
Total Questions: 93
Total Answers: 103

Location: South Korea
Member since Fri, Sep 11, 2020
4 Years ago
;