Solved

google maps geocoder does not retain new address passed in loop

Posted on 2008-10-01
3
576 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now