Solved

google maps geocoder does not retain new address passed in loop

Posted on 2008-10-01
3
578 Views
Last Modified: 2013-11-05
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

0
Comment
Question by:smueller72
  • 2
3 Comments
 
LVL 3

Expert Comment

by:JMT116
ID: 22614452
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
 
LVL 3

Author Comment

by:smueller72
ID: 22618913
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
 
LVL 3

Accepted Solution

by:
JMT116 earned 110 total points
ID: 22625875
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now