google maps geocoder does not retain new address passed in loop

the following code brings up '7100 e pleasant valley, independence, oh' in both info boxes rather than the correct address.

alerting the address before geocoder alerts the correct address, but inside the callback alerting the address always alerts '7100 e. pleasant valley, independence, oh'. why is the other address in the addresses array not being passed in the callback the second time around?
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA5idgfsNJWcmuDuij5AZQQRRQzVMreEd-TAb1rwE4ekdeuRBKrRQnMstWD0shxisrk5n5Qama4i2a7A" type="text/javascript"></script>
<!-- development key ABQIAAAA5idgfsNJWcmuDuij5AZQQRRQzVMreEd-TAb1rwE4ekdeuRBKrRQnMstWD0shxisrk5n5Qama4i2a7A -->
<!-- production key ABQIAAAA5idgfsNJWcmuDuij5AZQQRRpucpV2qqoB7MlwE6IghuvoLAhqxQNWlUogPkBZC-QC0ungs1q6K8X6Q -->
<script>
$().ready(function(){
  load();
});
</script>
  <script type="text/javascript">
    //<![CDATA[
    function load() {
      if (GBrowserIsCompatible()) {
        
        function createTabbedMarker(point,address){
          var marker = new GMarker(point);
          GEvent.addListener(marker,"click",function(){
            var tabs = [];
            tabs.push(new GInfoWindowTab("Details", address));
            tabs.push(new GInfoWindowTab("Directions","<div class=\"gmapsdirections\" style=\"width:200px;\"><form action=\"http://maps.google.com/maps\" method=\"get\" target=\"_blank\"><label for=\"saddr\">Starting Address:</label><br/><input name=\"saddr\" id=\"saddr\" size=\"20\" type=\"text\"/><input value=\"Go\" type=\"submit\" /><input name=\"daddr\" value=\""+ address +"\" type=\"hidden\"/><input name=\"hl\" value=\"en\" type=\"hidden\"/></form></div>"));
            marker.openInfoWindowTabsHtml(tabs);
          });
          return marker;
        }
        
        var addresses = new Array(
          new Array("1729 Harbor Street","Ogilvie, MN 56358"),
          new Array("7100 E Pleasant Valley","Independence, OH 44131")
        );
        
        var map = new GMap2(document.getElementById("gmap"));
        map.addControl(new GSmallMapControl());
        
        for (i=0;i<addresses.length;i++){
          var address1 = addresses[i][0];
          var address2 = addresses[i][1];
          var address = address1 + ", " + address2;
          var geocoder = new GClientGeocoder();
          geocoder.getLatLng(
            address,
            function(point){
              map.setCenter(point, 3);
              var marker = createTabbedMarker(point,address);
              map.addOverlay(marker);
            }
          );
        }
        
      }
    }
    //]]>
    </script>
<div id="gmap"></div>
<div style="clear:both;padding:10px;"></div>

Open in new window

LVL 3
smueller72Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
JMT116Connect With a Mentor Commented:
I've seen errors with geo coding if you do the geo codes too close together.  Trying waiting 1 second before looping to give time to run the geo code.

I still think it is advisable to geo code once and store the gps coordinates for the actual production page.
0
 
JMT116Commented:
I think Google limits how many geocodes you can do a day.  Here are two articles that will support that.  http://econym.googlepages.com/geomulti.htm
http://groups.google.com/group/Google-Maps-API/browse_thread/thread/c24dc2c5514bd818

Basically you could get errors when adding multiples like this because you search to rapidly that one of the addresses didn't come up.
0
 
smueller72Author Commented:
the limit is around 15,000/day. i was looking as to why the address is 'caching' or not clearing. i tried emptying google cache and that did not work. geocoding was not limited as it was pulling the second address in the array; not the first.
0
All Courses

From novice to tech pro — start learning today.