On 29 June 2010 19:31, jayjayc <[email protected]> wrote:
> I am trying to geocode a couple of addresses passed by a url and use
> the MarkerManager to display them.
>
> My map will center around the location, but will not place the
> marker(s).
>
> Here is a copy with a single address as an example:
> http://sharepoint.advancedtelesystems.com/public/Downloads/MapIntegration.html?address=2%20hathaway%20st%20providence%20ri%2002907
This is because the geocoder is asynchronous.
The map is centred because the callback function does that when it
gets the point and pushes the marker on to the array.
However, the "batch" array is added to the marker manager before the
callback function has been called, so at that point it's empty. When
the geocode result is returned, the map is centred and the marker is
pushed on to the array; but then nothing else happens to the array.
You need to ensure that everything which needs to happen to geocoder
data happens within the callback function.
Since you know the length of arr2, you could include a test in your
loop and only action the centring and marker-adding when you're done:
if (i==arr2.length-1) {
gmap.setCenter(point);
mgr.addMarkers(batch, 13);
mgr.refresh();
}
...but all that needs to go into the callback function, so every time
a result is processed, the code asks "Is this the last one to come
back?" and finishes the map if it is.
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.