views:

101

answers:

2
var markersArray = new Array();    
function clearOverlays(){
      if(markersArray){
       for (i in markersArray) {
        markersArray[i].setMap(null);
      }
      }
      }

this is pretty much copied off the google maps v3 documentation... but it doesn't work. :/

this is where the function is implemented:

 function TCGetLatLong(address){
   var geo = new google.maps.Geocoder;
   var lat;
   var lng;

   geo.geocode({'address':address},function(results, status){
     if (status == google.maps.GeocoderStatus.OK) {
    clearOverlays();
    addMarker(results[0].geometry.location, true, true, 16, "new", 0, "", "");
     } else {
    alert("Geocode was not successful for the following reason: " + status);
     }

    });

  }

and this is the bit where I add the marker in the addMarker function:

   marker = new google.maps.Marker({
  position: location,
  draggable: draggable,
  title: "Your new listing",
  map: map
   });

   markersArray.push(marker);

   google.maps.event.addListener(marker, 'dragend', function() {     
  infowindow.open(map,marker);
  document.getElementById('lat').value = marker.position.lat();
  document.getElementById('long').value = marker.position.lng();
   });
   google.maps.event.addListener(marker, 'dragstart', function(){ infowindow.close(); });
   infowindow.open(map,marker);
   google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
                 });

Any help will be excellent... thank you.

A: 

Experiencing a similar problem - I think the markers array is not fully populated before the map load event completes in my case. I throw a js alert as the last command in my script that reads the array lenght, it comes back as 0. But, if I add in another js alert tied to a command button that i click after the page loads, I can read 1050 records in the array.

mrjake
A: 

Still haven't got an answer, but managed to get around it annoyingly.

Thomas Clayson