LatLngBounds order

333 views
Skip to first unread message

jplozano

unread,
Mar 3, 2011, 8:43:49 AM3/3/11
to Google Maps JavaScript API v3
Hi everybody,

I'm have this code:

var latlngbounds = new google.maps.LatLngBounds(A, B);
mapt.fitBounds(latlngbounds);

For example, A = London and B = Barcelona gives me http://prntscr.com/1lqs5
But when I change it to: A = London and B = Montevideo, it gives me
http://prntscr.com/1lqsc (map splitted)

I have read that this issue depends on the order of A and B. If I
reorder the arguments resulting in LatLngBounds(Montevideo, London)
instead of LatLngBounds(London, Montevideo) it works just fine.

The problem with all this is that A and B are random based on the user
input, so I have no clue when to switch from A,B to B,A or viceversa.

This is driving me crazy!!!
Thanks in advance.

Juan

geoco...@gmail.com

unread,
Mar 3, 2011, 2:23:08 PM3/3/11
to Google Maps JavaScript API v3
On Mar 3, 5:43 am, jplozano <jploza...@gmail.com> wrote:
> Hi everybody,
>
> I'm have this code:
>
> var latlngbounds = new google.maps.LatLngBounds(A, B);
> mapt.fitBounds(latlngbounds);
>
> For example, A = London and B = Barcelona gives mehttp://prntscr.com/1lqs5
> But when I change it to: A = London and B = Montevideo, it gives mehttp://prntscr.com/1lqsc(map splitted)
>
> I have read that this issue depends on the order of A and B. If I
> reorder the arguments resulting in LatLngBounds(Montevideo, London)
> instead of LatLngBounds(London, Montevideo) it works just fine.
>
> The problem with all this is that A and B are random based on the user
> input, so I have no clue when to switch from A,B to B,A or viceversa.
>
> This is driving me crazy!!!

Did you read the documentation on LatLngBounds?

http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds

LatLngBounds(sw?:LatLng, ne?:LatLng) Constructs a rectangle from the
points at its south-west and north-east corners

The two arguments are not A and B, they are SouthWestCorner and
NorthEastCorner.

If you want a bounds object that contains two arbitrary points, use
LatLngBounds.extend on an empty bounds object.

-- Larry


> Thanks in advance.
>
> Juan
Reply all
Reply to author
Forward
0 new messages