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!
To drop a pin on Google Maps when using an Android device: Open the Google Maps app. Either search for an address or scroll around the map until you find the location you want. Long-press on the screen to drop a pin.
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 }); }
In 2017, the solution is:
map.addListener('click', function(e) { placeMarker(e.latLng, map); }); function placeMarker(position, map) { var marker = new google.maps.Marker({ position: position, map: map }); map.panTo(position); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With