Google-maps – Add marker to Google Map on Click

google mapsgoogle-maps-api-3

I'm surprisingly struggling to find a very simple example of how to add a marker(s) to a Google Map when a user left clicks on the map.

I have looked around for the past couple of hours, and consulted the Google Maps API documentation, and would appreciate some help!

Best Answer

After much further research, i managed to find a solution.

google.maps.event.addListener(map, 'click', function(event) {
   placeMarker(event.latLng);
});

function placeMarker(location) {
    var marker = new google.maps.Marker({
        position: location, 
        map: map
    });
}