Latest

Thursday, July 6, 2017

Use Google Maps marker coordinates as form input

Asked by: Michiel van Nesselrooij


From the below javascript function, I get a javascript variable marker with coordinates when the user clicks a position on the map.

var marker;
function placeMarker(location) {
  if ( marker ) {
    marker.setPosition(location);
  } else {
    marker = new google.maps.Marker({
      position: location,
      map: map
    });
  }
}
google.maps.event.addListener(map, 'click', function(event) {
  placeMarker(event.latLng);
});

Question How can these coordinates be used as form input?

<form method="POST" action="/authors" target="" enctype="multipart/form-data">
   ...
</form>


Source

No comments:

Post a Comment

Adbox