Using Marker Manager With Ajax Call

584 views
Skip to first unread message

mike osterhout

unread,
Dec 1, 2010, 4:07:44 PM12/1/10
to google-map...@googlegroups.com
I have a tricky problem. I have code like this

$.get('/test.xml', function(xml){
   
   //use xml to create icons and markers
   
});

//I am then forced to use a setTimeout to ensure that this call is finished
//campusMarkers are created above...
setTimeout("addMarkers(markers)", 800);
//this will fail
addMarkers(markers);


IS THERE ANYWAY TO DO THIS WITHOUT A TIMEOUT? Maybe there is an event I can attach onto so that I know my markers are generated before I try to add them to the map

geoco...@gmail.com

unread,
Dec 1, 2010, 4:37:09 PM12/1/10
to Google Maps JavaScript API v3
On Dec 1, 1:07 pm, mike osterhout <mikeosterh...@gmail.com> wrote:
> I have a tricky problem. I have code like this
>
> $.get('/test.xml', function(xml){
>
> //use xml to create icons and markers

>

Put your call to add the markers you created to the marker manager
here.

> });
>
> //I am then forced to use a setTimeout to ensure that this call is
> finished
> //campusMarkers are created above...
> setTimeout("addMarkers(markers)", 800);
> //this will fail
> addMarkers(markers);
>
> IS THERE ANYWAY TO DO THIS WITHOUT A TIMEOUT?

Yes. See above.

-- Larry

mike osterhout

unread,
Dec 1, 2010, 5:12:20 PM12/1/10
to google-map...@googlegroups.com
Unfortunately it still needs a timeout... In my actual code I have the setTimeout within the ajax callback function.

to be more specific I could place

markerManager.addMarker(marker, marker.minZoom, marker.maxZoom);

directly in my callback function and I will get the following error, or something similar from markermanager...
Uncaught TypeError: Cannot call method 'fromLatLngToDivPixel' of undefined

Would be better if I could only add the markers when I know makermanager is ready.

Thanks tho.

geoco...@gmail.com

unread,
Dec 2, 2010, 1:30:13 AM12/2/10
to Google Maps JavaScript API v3
Sounds like you need to wait for the projection to be loaded. I think
I saw a post discussing this problem, but I wasn't able to find it
with a quick search.

I can't do more than speculate without a link to the patient.

-- Larry

>
> Thanks tho.

Ciul

unread,
Dec 2, 2010, 4:06:50 AM12/2/10
to Google Maps JavaScript API v3
Excuse me, I kinda had similar problem and well:

Do the markers have an InfoWindow attached to them?

If that's the case, you could use the domReady event from InfoWindows.

...
from google.maps.InfoWindow class

Event / Returns / Description
domready None This event is fired when the <div> containing the
InfoWindow's content is attached to the DOM. You may wish to monitor
this event if you are building out your info window content
dynamically.
...

mike osterhout

unread,
Dec 2, 2010, 8:41:47 AM12/2/10
to google-map...@googlegroups.com
It turns out you have to wait for marker manager to be ready. So after you create the markerManager you have to create a custom event listener that looks like this.

google.maps.event.addListener(markerManager, 'loaded', function() {

//place ajax call in here

});

mike osterhout

unread,
Dec 2, 2010, 8:42:34 AM12/2/10
to google-map...@googlegroups.com

geoco...@gmail.com

unread,
Dec 2, 2010, 9:33:24 AM12/2/10
to Google Maps JavaScript API v3
That was sort of what I remembered, I just couldn't find the post that
said that, and when I looked for the documentation, I didn't see that
mentioned, still don't for that matter:
http://google-maps-utility-library-v3.googlecode.com/svn/tags/markermanager/1.0/docs/reference.html

-- Larry


>
>
>
>
>
>
> });
Reply all
Reply to author
Forward
0 new messages