Following code is to track user location,
var curr_loc; //global varible
function displayLocation(loc) {
currLat = loc.coords.latitude;
currLon = loc.coords.longitude;
curr_loc = currLat + "," + currLon;
alert(curr_loc); //Displaying latitude and longitude values
}
function foo() {
navigator.geolocation.getCurrentPosition(displayLocation);
alert(curr_loc); //undefined
}
foo();
How can I access location values in foo method.