Here is my code:
var lat;
$(document).ready(function() {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
console.log("inside", lat);
});
console.log("outside", lat);
});
When I run it (see jsfiddle) the console shows this:
outside undefined
inside 55.8509728
Not sure if it matters, but I noticed that "outside" value is always displayed first even though it goes after the "inside" in the code.
Can someone be so kind to explain why I cannot get (or probably set?) that lat
variable?