Can't pass coordinates through localstorage

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

Can't pass coordinates through localstorage



I'm trying to make a Google Maps application, where you can enter you location in an input and then get redirected to another page with a map that shows your location.
The problem is that when I'm saving the coordinates in a localstorage on one Javascript file its not able to read it out on the other one.
Any ideas?



Heres my Code



Saving data:


var location = document.getElementById('location-input').value;
axios.get('https://maps.googleapis.com/maps/api/geocode/json',
params:
address:location,
key:'AIzaSyBsOGGokaWGD3m5y4uYYG_sv7U1T9nZ5HI'

)
.then(function(response)
// Log full response
console.log(response);

var lat = response.data.results[0].geometry.location.lat;
var lng = response.data.results[0].geometry.location.lng;

sessionStorage.setItem('lat', lat);
sessionStorage.setItem('lng', lng)

console.log(lat)
)
.catch(function(error)
console.log(error);
)`



Retrieving data:


function initMap()
var lat = sessionStorage.getItem('lat');
var lng = sessionStorage.getItem('lng')
console.log(lat)
)}



I want to add that passing a number directly or passing a word is no problem.





Any errors in the JavaScript console? Please provide a Minimal, Complete, and Verifiable example that demonstrates your issue.
– geocodezip
15 hours ago






nope no errors.
– Shilloko
15 hours ago




2 Answers
2



lat & lng are functions of a google.maps.LatLng.
Call them to get the value:


lat


lng


google.maps.LatLng


var lat = response.data.results[0].geometry.location.lat();
var lng = response.data.results[0].geometry.location.lng();



live proof of concept:





It still doesnt work. I only get null as a response even though Its able to log the output on the first webpage.
– Shilloko
15 hours ago





It works for me: store, retrieve. If these working examples don't help, please provide a Minimal, Complete, and Verifiable example that demonstrates your issue.
– geocodezip
14 hours ago



better to encode your data before pssing them


var coord = JSON.stringify(
lat : response.data.results[0].geometry.location.lat();
lng : response.data.results[0].geometry.location.lng();
);
sessionStorage.setItem('coord', coord);





now i always get the coordinates of my the town from my first input. it never changes
– Shilloko
14 hours ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

PySpark count values by condition

Trying to Print Gridster Items to PDF without overlapping contents