Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow user to place marker on a google map

I'm looking for a way to allow a user to place a marker on a Google map and then get the co-ordinates so I can email them to a user.

Is it possible to allow users to do this on the fly? I've seen here and understand I can do this using longitude and Latitude. So using the above method can I get a Longitude and Latitude from a users click?

like image 739
LiamB Avatar asked Jan 18 '23 10:01

LiamB


1 Answers

You can achieve this using the following code:

google.maps.event.addListener(map, 'click', function( event ){
  alert( "Latitude: "+event.latLng.lat()+" "+", longitude: "+event.latLng.lng() ); 
});

The map variable is your google.maps.Map instance. Every time the user clicks the map an alert box will display the coordinates of the place he clicked.

like image 174
Stefan Kovachev Avatar answered Jan 28 '23 15:01

Stefan Kovachev