its been a while since i have programmed in Javascript. Basically i want to get geo location of a person and then pass the variables which are the coords into another function which will do something for me. but what happens is, javascript is running along and basically i get undefined as expected. how do i make a simple call back on getLocation function? I want as getLocation finished and lat and lng are defined do some function, i want it in the alert Thanks.
var x = document.getElementById("demo");
var lat = 0;
var lng = 0;
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
}
getLocation();
alert(lat);