I tried to get these variables:
Geoposition.coords.latitude
Geoposition.coords.longitude
from navigator.geolocation.getCurrentPosition
by the way:
function getPosition() {
"use strict";
var coordinates = {
latitude: null,
longitude: null,
error: false,
testData: 'Hello, world!'
}
function success (pos) {
coordinates.latitude = pos.coords.latitude;
coordinates.longitude = pos.coords.longitude;
coordinates.testData = 'I am John';
console.log(coordinates); //here it is ok, latitude,longitude and testData were recorded
}
function fail(error){
coordinates.error = true;
}
navigator.geolocation.getCurrentPosition(success, fail);
return coordinates; // but here it is no ok: function returns "coordinates" in initial state (null, null, false, "Hello, world!")
}
As far as I know, in JavaScript objects do not clone, but here it seems like they do. What am I doing wrong? And how can I use coords out of callback "success"?