Posted By

marzsman on 05/18/11


Tagged

google maps javascriptmarkers


Versions (?)

Add marker Google maps on click


 / Published in: JavaScript
 

Add draggable markers on a Google map with a click, remove marker on click

  1. google.maps.event.addListener(map, 'click', addPoint);
  2.  
  3. function addPoint(event) {
  4. var marker = new google.maps.Marker({
  5. position: event.latLng,
  6. map: map,
  7. draggable: true
  8. });
  9. markers.push(marker);
  10. google.maps.event.addListener(marker, 'click', function() {
  11. marker.setMap(null);
  12. for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
  13. markers.splice(i, 1);
  14. });
  15. google.maps.event.addListener(marker, 'dragend', function() {
  16.  
  17. });
  18. }

Report this snippet  

You need to login to post a comment.