I am running following javascript as a test using jsfiddle.net -
var v1=1;
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
alert('Your current position is:');
alert('Latitude : ' + crd.latitude);
alert('Longitude: ' + crd.longitude);
alert('More or less ' + crd.accuracy + ' meters.');
v1=crd.latitude;
alert(v1);
};
function error(err) {
alert('ERROR(' + err.code + '): ' + err.message);
};
alert(v1);
navigator.geolocation.getCurrentPosition(success, error, options);
alert(v1); //removing this makes the code work
The code works fine until the last alert is put in place. The success function isn't invoked in that case. I am baffled if it's a global variable declaration issue or the way getCurrentPosition is being invoked. All I want is to have the longitude and latitude values in a variable that I can use later. Newbie here. Any pointers?