I want to update my global variables, which are intended to hold values for my coordinates. They have their values only inside the function, not outside (globally). To be honest it's driving me crazy. If I want to use their values I have to call function within a function... which makes no sense to me (I prefer calling the function separately). Below is my code:
var lat = '';
var lon = '';
navigator.geolocation.getCurrentPosition(succes, error);
function succes(position){
var crd = position.coords;
lat = crd.latitude;
console.log('inside: '+lat);
}
function error(err){
console.warn(err.code + ': ' + err.message);
}
console.log('outside: '+lat);
Any idea why it happens?
Edit: I now realized, that the order of executing is not like I wanted. Why?