M.Dos
M.Dos

Reputation: 3

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);

Upvotes: 0

Views: 135

Answers (2)

Dario
Dario

Reputation: 6280

You need to invoice lat and lng which are functions:

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

Upvotes: 4

Vicente Olivert Riera
Vicente Olivert Riera

Reputation: 1220

lat and lng are functions. Try to call them like this:

event.latLng.lat() and event.latLng.lng()

Upvotes: 3

Related Questions