Answer the question
In order to leave comments, you need to log in
How to save coordinates to an array in a separate file?
Hello, in the application I enter an address and in return I get the coordinates and the name of the autonomous region.
I get 3 lines in the output
results[0].formatted_address.value
results[0].address_components[2].long_name.value
results[0].geometry.location.value
var Points = [
{
object: "ул.Стромынка, д.7",
district: "Центральный автономный округ",
point: [56.0091086,92.8714365]
},
]
Answer the question
In order to leave comments, you need to log in
var Points = [ /* коллекция точек */ ];
function save(points) {
localStorage.setItem('points', JSON.stringify(points));
}
function load() {
var points = localStorage.getItem('points');
return points ? JSON.parse(points) : [];
}
The data needed after the page is reloaded must be stored somewhere.
And JS is a client-side language, so you can save data using it in several ways some identifier?)
2. In a cookie, but then the data will be available only on the current computer, in the current browser (+ as much time as you specify)
3. In localStorage - the storage method is identical to cookies, the time is unlimited.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question