title: geocoder call does not work in for loop
body: <p>I am working on project of tracking multiple devices with their last location address, name, time etc. To display address, I'm using Reverse Geocoding (Last location lat long comes from mysql db). Code works for single device tracking but when I am trying to display all devices at a time, it displays only first devices address. After that, for loop stops. I don't get idea that where is I'm wrong. Point me my mistake and correct me if anyone knows. Here is my full javascript code.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;    
  function load() {
              var abc;
              var pqr;
              function getLocation() {
                  navigator.geolocation.getCurrentPosition(showPosition);
              }
              function showPosition(position) {
                  abc = position.coords.latitude;
                  pqr = position.coords.longitude;
                  googlemap(abc, pqr);
              }
              getLocation();
          }
  
          function googlemap(lat, lng) {
              var x = document.getElementById("myForm");
              var text = '';
              for (var k = 0; k &lt; x.length; k++) {
                  text += x[k].value;
                  if (k != (x.length - 1)) {
                      text += ",";
                  }
              }
  
              var names = new Array();
              var colors = new Array();
              var imeis = new Array();
              var times = new Array();
              var point;
  
              var map = new google.maps.Map(document.getElementById("map"), {
                  center: new google.maps.LatLng(lat, lng),
                  zoom: 6,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
              });
  
              var iconsetngs = {
                  path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
              };
  
              setInterval(function () {
                  downloadUrl("points.php?data=" + text, function (data) {
                      var xml = data.responseXML;
                      var points = xml.documentElement.getElementsByTagName("point");
                      flightPlanCoordinates = new Array();
                      var imo = '';
                      var w = -1;
                      for (var i = 0; i &lt; points.length; i++) {
                          if (parseFloat(points[i].getAttribute("imei")) != imo) {
                              names.push(points[i].getAttribute("name"));
                              times.push(points[i].getAttribute("time"));
                              colors.push(points[i].getAttribute("color"));
                              imeis.push(parseFloat(points[i].getAttribute("imei")));
                              imo = parseFloat(points[i].getAttribute("imei"));
                              w++;
                              flightPlanCoordinates[w] = new Array();
                          }
                          point = new google.maps.LatLng(
                                  parseFloat(points[i].getAttribute("lat")),
                                  parseFloat(points[i].getAttribute("lon"))
                                  );
                          flightPlanCoordinates[w].push(point);
                      }
  
                      for (var j = 0; j &lt; imeis.length; j++) {
                          var flightPath = new google.maps.Polyline({
                              path: flightPlanCoordinates[j],
                              geodesic: true,
                              strokeColor: colors[j],
                              strokeOpacity: 1.0,
                              strokeWeight: 2,
                              icons: [{
                                      icon: iconsetngs,
                                      repeat: '35px',
                                      offset: '100%'}]
                          });
  
                          var geocoder = new google.maps.Geocoder();
                          geocoder.geocode({'latLng': flightPlanCoordinates[j][(flightPlanCoordinates[j].length) - 1]}, function (results, status) {
                              if (status == google.maps.GeocoderStatus.OK) {
                                  if (results[1]) {
                                      map.setZoom(7);
                                      var marker = new google.maps.Marker({
                                          position: flightPlanCoordinates[j][(flightPlanCoordinates[j].length) - 1],
                                          map: map
                                      });
                                      var contentString = names[j] + times[j] + results[1].formatted_address;
                                      var infowindow = new google.maps.InfoWindow({
                                          content: contentString
                                      });
                                      infowindow.open(map, marker);
                                  } else {
                                      alert('No results found');
                                  }
                              } else {
                                  alert('Geocoder failed due to: ' + status);
                              }
                          });
  
                          flightPath.setMap(map);
                          geocoder.setMap(map);
  
                      }
                  });
                  names = [];
                  imeis = [];
                  times = [];
                  colors = [];
                  flightPlanCoordinates = [];
              }, 10 * 1000);
          }
  
  
          function downloadUrl(url, callback) {
              var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
              request.onreadystatechange = function () {
                  if (request.readyState == 4) {
                      request.onreadystatechange = doNothing;
                      callback(request, request.status);
                  }
              };
              request.open('GET', url, true);
              request.send(null);
          }
  
          function doNothing() {
          }    &lt;/script&gt;
  &lt;body onload="load();"&gt;
      &lt;form method="post" id="myForm" class="myForm" name="myForm"&gt;
          &lt;select name="dvc"&gt;
              &lt;option value="all"&gt;All&lt;/option&gt;
              &lt;?php
              $qry = mysql_query("SELECT * FROM devices");
              while ($row = mysql_fetch_array($qry)) {
                  ?&gt;
                  &lt;option value="&lt;?php echo $row['device_imei']; ?&gt;"&gt;&lt;?php echo $row['device_name']; ?&gt;&lt;/option&gt;
              &lt;?php } ?&gt;
          &lt;/select&gt;
          &lt;input type="date" name="exct" value="&lt;?php echo $date; ?&gt;"/&gt;
          From:
          &lt;input type="date" name="from" /&gt;
          To:
          &lt;input type="date" name="to" /&gt;
      &lt;/form&gt;
      &lt;button onclick="load();"&gt;Submit&lt;/button&gt;
  
      &lt;div id="map" style="width: 100%; height: 100%"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>