Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a problem with the asynchronous nature of the geocoder, and if you add many addresses you will have a problem with the geocoder quota/rate limits (particularly since your code doesn't look at the return status of the geocoder).</p> <p>All these questions are related:</p> <ul> <li><a href="https://stackoverflow.com/questions/4236522/google-maps-api-v3-info-window-displaying-same-information-for-all-the-markers">Google Maps Api v3: Info window displaying same information for all the markers on the map</a></li> <li><a href="https://stackoverflow.com/questions/6866028/gmaps-api-v3-multiple-markers-infowindow-problem">GMaps API V3 - Multiple Markers &amp; InfoWindow</a></li> <li><a href="https://stackoverflow.com/questions/12148783/google-map-multiple-inforwindow-does-not-work">Google Map multiple infowindow does not work</a></li> </ul> <p>The simplest solution is to use function closure to associate the call to the geocoder with the returned result:</p> <pre><code>geocodeAddress(xmldata) { var address = xmldata.getElementsByTagName('address')[0].firstChild.data; var city = xmldata.getElementsByTagName('city')[0].firstChild.data; var address_google_map = address + ', ' + city + ', ON'; var info_text = address + '&lt;br /&gt;' + city + ' ON'; geocoder.geocode ({'address': address_google_map}, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { createMarker(results[0].geometry.location, info_text); } else { alert("geocode of "+ address +" failed:"+status); } }); } </code></pre> <p>And a createMarker function to associate the infowindow content with the marker:</p> <pre><code>function createMarker(latlng, html) { var marker = new google.maps.Marker ({ map: map, position: latlng }); google.maps.event.addListener(marker, 'click', function() { info_window.setContent(html); info_window.open(map, marker); }); } </code></pre> <p>Makes your for loop:</p> <pre><code>for (var i = 0; i &lt; markers.length; i++) { geocodeAddress(markers[i]); } </code></pre> <p><a href="http://www.geocodezip.com/v3_SO_multipleGeocodedMarkersFromXml.html" rel="nofollow noreferrer">Working example</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload