Add marker Google maps on click


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.