M.Dos M.Dos - 1 year ago 57
jQuery Question

save Lat and Lng when click on map

I'm trying to use the below code to save "lat" and "lng" value when user clicks on map but

I get "undefined" for both lat and lng !!!

"latStorage" is the storage name where I want to store the lat

"lngStorage" is the storage name where I want to store the lng

var placedMarkers = 0;
var availableMarkersToPlace = 1;
setTimeout( function(){
if(placedMarkers >= availableMarkersToPlace)
var map = Appery("google_map").gmap;
google.maps.event.addListener(map, 'click', function(event) {
localStorage.setItem('latStorage', event.latLng.lat);
localStorage.setItem('lngStorage', event.latLng.Lng);
alert (event.latLng);
}, 1000);

Answer Source

You need to invoice lat and lng which are functions:

localStorage.setItem('latStorage', event.latLng.lat());
localStorage.setItem('lngStorage', event.latLng.lng());