Here is my final code as well as working link, for those
interested....

Thanks again for the help:

Link: http://31st.com/google-maps/geocode2a.html

Code:

<script type="text/javascript">
    //<![CDATA[


                function showAddress(address) {
                if (GBrowserIsCompatible()) {

                var map = new GMap2(document.getElementById("map"));
        geocoder = new GClientGeocoder();
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(36.16693,-86.784439), 12);



          GDownloadUrl("gen_xml.php", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName
("marker");


                  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(
                                address,
                                function(point) {
                                  if (!point) {
                                        alert(address + " not found");
                                  } else {

                                        var marker = createMarker(point, name, 
address, type);
                                        map.addOverlay(marker);

                                  }
                                }
                          );
                          }

          });

        }}

                function createMarker(point, name, address, type) {
                var marker = new GMarker(point);
                var html = "<b>" + name + "</b> <br/>" + address + "<br/>" + 
point;
                GEvent.addListener(marker, 'click', function() {
                marker.openInfoWindowHtml(html);
                                });
                                return marker;
                }

    //]]>
  </script>



On Dec 31 2009, 8:59 am, chris <[email protected]> wrote:
> 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 ageocode
> > 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 thegeocoderequest.
>
> > 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