I'm trying to make a website which shows the longitude and latitude using the browser's navigator feature. When i run the code below I get Latitude:undefined
instead of Latitude:[My latitude]
. Can anyone help me out?
$(document).ready(function() {
var la;
var lg;
function getLocation() {
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(showPosition);
}
function showPosition(position) {
la = position.coords.latitude;
lg = position.coords.longitude;
}
document.getElementById("lat").innerHTML = "Latitude:" + la;
});