google maps. how to create a LatLngBounds rectangle (square) given coords of a central point

maiky picture maiky · Apr 19, 2011 · Viewed 14.7k times · Source

I have a point (X,Y) and I want to create a square , Google maps LatLngBounds object so to make geocode requests bias only into this LatLngBound region.

How can I create such a LatLngBounds square with center the given point? I have to find the NE and SW point. But how can I find it given a distance d and a point (x,y)?

Thanks

Answer

wprater picture wprater · Nov 4, 2012

You can also getBounds from a radius defined as a circle and leave the trig to google.

new google.maps.Circle({center: latLng, radius: radius}).getBounds();