Skip to content Skip to sidebar Skip to footer

Storing Google Map Markers And Selecting A Specific Marker From It

I have a webpage that receives AJAX data with values listing_id, lat, lng using $.getJSON. The callback function takes these series of values and creates a Google map marker for e

Solution 1:

When you create the markers, instead of using an array, can you use a hash table?

http://jsfiddle.net/j9J8x/

var markers = {};

    //id goes in place of 1234
    n = 1234;
    markers[n] = new google.maps.Marker({
      map: map,
      position: new google.maps.LatLng(0,0)
    });

    s = '2234'
    markers[s] = new google.maps.Marker({
      map: map,
      position: new google.maps.LatLng(20,0)
    });

    google.maps.event.addListener(map, 'click', function(event) {
      k = 1234;
      markers[k].setMap(null);
      markers['2234'].setMap(null);
    });
  }

Post a Comment for "Storing Google Map Markers And Selecting A Specific Marker From It"