Home » Javascript » How to add a draggable pin on Google Maps when custom button is pressed?

How to add a draggable pin on Google Maps when custom button is pressed?

Posted by: admin July 12, 2018 Leave a comment

Questions:

I’m trying to add a draggable pin to the map after the user clicks the custom button. I’m using a Google Map.
I planned to use a function that will show the pin on the map and after that, the user will able to drag it over the map and drop it somewhere.

//Setup the click event listeners
                    google.maps.event.addDomListener(controlUI, 'click', function () {

      });

P.S. I will need the longitude and latitude of the dropped pin.

Screenshot of the actual Google Map with a custom red button

Answers: