I want to store the geolocation but when I go and store the latitude and longitude in variables outside the scope they won't store. Does anybody know why this is the case? I've tried with undefined variables too but that hasn't worked either.
Here's my code:
$(document).ready(function(){
var location = {lat:'', lon:''};
function updateLocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
location.lat = position.coords.latitude;
location.lon = position.coords.longitude;
});
}
}
updateLocation();
$("#data").html("lat: " + location.lat + " lon: " + location.lon);
});