getBounds is null??

435 views
Skip to first unread message

Nexis

unread,
Sep 24, 2009, 6:43:36 AM9/24/09
to Google Maps JavaScript API v3

I'm trying to add markers on google map.

I'm selecting one point and adding this on the google map.

This is my center point. Then i'm trying to get minimum and maximum
lng and lat values from map with getBounds method. But it's not
working. It returns null.


var marker = createMarker(point);
// This is my center point. And I'm setting zoom level as 14
gsmapsrc.setCenter(point, 14);
google.maps.event.addListener(gsmapsrc, 'bounds_changed',
BoundsChanged());


But when event is fired i'm getting getBounds is null
exception.
function BoundsChanged() {

var SouthWestlat = gsmapsrc.getBounds().getSouthWest().lat();
var SouthWestlng = gsmapsrc.getBounds().getSouthWest().lng();
var NorthEastlat = gsmapsrc.getBounds().getNorthEast().lat();
var NorthEastlng = gsmapsrc.getBounds().getNorthEast().lng();
}

Esa

unread,
Sep 24, 2009, 7:43:58 AM9/24/09
to Google Maps JavaScript API v3
You could try the new 'idle' event instead of 'bounds_changed'.

'idle' is fired slightly later.

Nexis

unread,
Sep 24, 2009, 8:05:02 AM9/24/09
to Google Maps JavaScript API v3
This code isn't working.
google.maps.event.addListener(gsmapsrc, 'bounds_changed',
BoundsChanged());

But this is working
setTimeout(BoundsChanged()', 500);

???

Nexis

unread,
Sep 24, 2009, 8:35:33 AM9/24/09
to Google Maps JavaScript API v3
sorry but idle event isn't working :((

Esa

unread,
Sep 24, 2009, 9:09:36 AM9/24/09
to Google Maps JavaScript API v3


On Sep 24, 3:35 pm, Nexis <umitkav...@gmail.com> wrote:
> sorry but idle event isn't working :((

Do you mean that it is fired too late? Or is it not fired at all with
a certain browser?

I can see it fired after each map movement. Like 'moveend' of v2.
http://koti.mbnet.fi/ojalesa/v3/v3events.htm

Nexis

unread,
Sep 24, 2009, 9:11:15 AM9/24/09
to Google Maps JavaScript API v3
it's fired but getBounds returns null.

Mike Williams

unread,
Sep 24, 2009, 9:25:40 AM9/24/09
to google-map...@googlegroups.com
Wasn't it Nexis who wrote:
>
>This code isn't working.
> google.maps.event.addListener(gsmapsrc, 'bounds_changed',
>BoundsChanged());

That syntax tells the browser to call BoundsChanged() *immediately* and
expects it to return a function reference. When the event triggers, the
callback function passes control to whatever BoundsChanged() returned.
That's not what you want.


In this case you can write

google.maps.event.addListener(gsmapsrc, 'bounds_changed',BoundsChanged);

Without the (), "BoundsChanged" is a function reference.
With the (), "BounsdChanged()" calls the function now and uses whatever
it returns as the function reference.

In the general case, where you have variables to pass from *your* code
to the callback function, you'd write

function createListener(foo,bar,baz) {
google.maps.event.addListener(gsmapsrc, 'bounds_changed', function() {
BoundsChanged(foo,bar,baz);
});
}

using the outer function to hold Function Context on the variables.

--
Mike Williams
Gentleman of Leisure

Nexis

unread,
Sep 24, 2009, 10:00:34 AM9/24/09
to Google Maps JavaScript API v3
thanks for solving my problem =)
Reply all
Reply to author
Forward
0 new messages