Excellent advice, much thanks...

Researching the info you have provided....

~Chris



On Dec 31, 8:50 am, Andrew Leach <[email protected]>
wrote:
> On Dec 31, 2:35 pm, chris <[email protected]> wrote:
>
>
>
> > I have now have an issue where my markers do not pull the correct data
> > for "name", "address type", etc.... It uses one value for all.
>
> Although you have used a helper function to create your markers, so
> each GMarker object has its own point, name, address and type, there
> is an issue with the asynchronous nature of geocoding.
>
> You set "address", "type" and "name" and then fire off a geocode
> request. You then go round the loop again, set those variables and
> fire off another request. At some point, the first request returns and
> creates the marker: but by that stage, "address" doesn't contain the
> address which it did when that request was initiated.
>
> So you need a helper function to do the geocoding as well.
>
>    for (var i = 0; i < markers.length; i++) {
>      var address = markers[i].getAttribute("address");
>      var type = markers[i].getAttribute("type");
>      var name = markers[i].getAttribute("name");
>      addMarkerAtGeocode(address,type,name)
>    }
>
>   function addMarkerAtGeocode(address,type,name) {
>     geocoder.getLatLng(
>     // etc
>     }
>
> This obtains function closure on each iteration's address, type, name
> and keeps everything together with the geocode request.
>
> Note that a tight loop like this will run into rate problems once your
> markers array has more than ten or so elements. See Mike's page on
> geocoding athttp://econym.org.uk/gmap/geomulti.htm
>
> Andrew

--

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.


Reply via email to