What's the equivalent of the "load" Event?

911 views
Skip to first unread message

mp-

unread,
Jun 16, 2009, 6:14:31 PM6/16/09
to Google Maps JavaScript API v3
What's the equivalent of the "load" Event in version 3 of the API?

http://code.google.com/apis/maps/documentation/reference.html#GMap2.load

The benefit of "load" vs "tilesloaded" is that load fires immediately
once the Google map has been setup and tilesloaded only fires once the
maps has fully loaded the images.

pamela (Google Employee)

unread,
Jun 17, 2009, 1:01:12 AM6/17/09
to google-map...@googlegroups.com
Hi mp-

Depends. What is your use case for knowing when the map has loaded?

- pamela

mp-

unread,
Jun 17, 2009, 9:42:41 AM6/17/09
to Google Maps JavaScript API v3
It's for a real estate web site.

Once the map is loaded ("load" - yet not visible), I immediately
obtain the map bounds (viewable area). I then send those bounds to my
database to query which homes are located within the viewable area of
the map and then display the homes are markers on the map.

If I wait until the map is fully visibility loaded (tilesloaded),
there is a noticeable perceived slowness in rendering because it's not
until the map has fully loaded visually that I can query for the
homes.

The "load" Event from API v2 let's me cheat in a sense and get a head
start on when I can query my homes database.

I did once look into using the static maps HTTP api to obtain the map
bounds but that API doesn't have a callback functionality, so it's
unusable for AJAX applications.

What I ultimately want to do is be able to query my homes database
with the map bounds as soon as possible because right now - my web
application has to wait until the Google Maps fully loads until it can
do anything. (If I can serialize this process - that's ideal)

Make sense?

On Jun 17, 12:01 am, "pamela (Google Employee)" <pamela...@gmail.com>
wrote:

String

unread,
Jun 17, 2009, 11:13:37 AM6/17/09
to Google Maps JavaScript API v3
On Jun 17, 2:42 pm, mp- <miche...@gmail.com> wrote:

> Once the map is loaded ("load" - yet not visible), I immediately
> obtain the map bounds (viewable area).  I then send those bounds to my
> database to query which homes are located within the viewable area of
> the map and then display the homes are markers on the map.

Try the bounds_changed event - my experience is that fires once the
core map has loaded but before the tiles are necessarily done. Only
thing is, you'll need to detach your listener inside the handler, or
it'll fire again every time the map moves.

String

mp-

unread,
Jun 17, 2009, 11:20:55 AM6/17/09
to Google Maps JavaScript API v3
How do I "detach" the listener as you refer too?

@Pamela,

Can you confirm that the "bounds_changed" event fire immediately and
is the most appropriate event to use in my use case.

String

unread,
Jun 17, 2009, 2:25:17 PM6/17/09
to Google Maps JavaScript API v3
On Jun 17, 4:20 pm, mp- <miche...@gmail.com> wrote:

> How do I "detach" the listener as you refer too?

Keep track of the listener in a global var, like this:

window.loadListener = google.maps.event.addListener(map,
'bounds_changed', loadHandler);


Then in your handler, detach it like this:

function loadHandler() {
google.maps.event.removeListener(loadListener);
// Actual load-handling code goes here
};


String

mp-

unread,
Jun 18, 2009, 6:33:45 PM6/18/09
to Google Maps JavaScript API v3
@Pamela

Curious to know if my use case above for needing the API v2 "load"
event back in API v3 was of any help. See my previous comments above.

pamela (Google Employee)

unread,
Jun 21, 2009, 10:08:38 PM6/21/09
to google-map...@googlegroups.com
Hi mp-

The bounds_changed event is designed to fire when the bounds are first
available, please use that.

- pamela
Reply all
Reply to author
Forward
0 new messages