17

Using the Google Maps API, how can I get the latitude and longitude of the corners of the map display area?

That is, if my map is 300px wide and 400px tall, how can I find the lat-long of the points at (0,0) and (300,400)?

Matt Hampel
  • 5,088
  • 12
  • 52
  • 78

2 Answers2

14

Use getBounds(). From the doc:

Returns the the visible rectangular region of the map view in geographical coordinates.

That function returns exactly what you want: the southwest and northeast corners of your map. The first pair of coordinates are the lower left (southwest) coordinates and the second pair is the upper right (northeast) coordinates.

Paul Richter
  • 6,154
  • 2
  • 20
  • 22
Derek Swingley
  • 8,734
  • 5
  • 32
  • 33
  • (0,0) is likely intended to be the northwest corner, in which case Matt will need the latitude of the second coordinate, but the longitude from the first. – SingleNegationElimination Jul 05 '09 at 05:36
  • 1
    Good point, but I figured since we're talking about a map and not a generic screen, the origin would be the lower left, not the upper left. Either way, getBounds() will return the info Matt wants. It's just a matter of parsing it... – Derek Swingley Jul 05 '09 at 05:48
  • 5
    map.getBounds().getSouthWest().lng() = the west bound. map.getBounds().getNorthEast().lat() = the north bound, etc. – Chris B Jul 06 '09 at 15:41
1

In Android(Kotlin) you can try this,

val curentScreen: LatLngBounds =  mapview.getProjection().getVisibleRegion().latLngBounds

var northeast=curentScreen.northeast
var southwest=curentScreen.southwest
var center=curentScreen.center
Log.v("northeast LatLng","-:"+northeast)
Log.v("southwest LatLng","-:"+southwest)
Log.v("center LatLng","-:"+center)
Shirsh Shukla
  • 5,491
  • 3
  • 31
  • 44