M.Dos M.Dos - 1 year ago 71
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)
return;
placedMarkers++;
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);
placeMarker(event.latLng,map);
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());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download