troubleshooting Question

Incorrect item used in java sub-function for Maps

Avatar of dbasplus
dbasplusFlag for Australia asked on
.NET ProgrammingJava
2 Comments1 Solution450 ViewsLast Modified:
I have the following scripts that create markers on a Google map.

  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  <script type="text/javascript">
      function ShowAddresses(Addresses, PropertyIDs) {
          var myOptions = {
              zoom: 14,
              mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          var geocoder = new google.maps.Geocoder();
          var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
          var bounds = new google.maps.LatLngBounds();
          var myArray = Addresses.split(";");
          var IDs = PropertyIDs.split(";");
          for (var i = 0; i < myArray.length; i++) {
              var address = myArray[i];
              var propertyID = IDs[i];
              geocoder.geocode({ 'address': address }, function (results, status) {
                  if (status == google.maps.GeocoderStatus.OK) {
                      map.setCenter(results[0].geometry.location);
                      alert(propertyID);
                      var marker = new google.maps.Marker({
                          position: results[0].geometry.location,
                          title: results[0].formatted_address + "(" + propertyID + ")",
                          animation: google.maps.Animation.DROP,
                          url: "PropertyDetails.aspx?prop_i=" + propertyID,
                          map: map
                      });
                      google.maps.event.addListener(marker, "click", function () {
                          window.location = marker.url;
                      });
                      bounds.extend(results[0].geometry.location);
                  } else {
                      //alert("Geocode was not successful for the following reason: " + status);
                  }
              });
          }
      }
  </script>

I pass in delimited lists for address and property ID (these come from the database behind). I want to use the property id to reference the local page when clicked.

My issue is that the 'propertyID' used in the 'geocoder.geocode' is always the last item in the list. What is the best way to get the current propertyID to be used?
ASKER CERTIFIED SOLUTION
dbasplus

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros