Last active
September 7, 2016 15:46
-
-
Save Superbil/d0b73d05d0581fc9e1271551d4e88763 to your computer and use it in GitHub Desktop.
lat and lng can't set, because is null
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lat = document.getElementById("lat"); | |
var lng = document.getElementById("long"); | |
function getLocation() { | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition( | |
addPositionHandler, | |
errorHandler, | |
{highAccuracy: false, | |
maximumAge: 30000, // 30 seconds | |
timeout: 60000 // 1 minute | |
}); | |
} | |
}; | |
function errorHandler(err) { | |
console.warn('ERROR(' + err.code + '): ' + err.message); | |
}; | |
function addPositionHandler(position) { | |
var crd = position.coords; | |
var plat = crd.latitude; | |
var plong = crd.longitude; | |
lat.value = plat; // lat is null | |
lng.value = plong; // lng is null | |
console.log('Lat: ' + plat + ' Long: ' + plong); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getLocation() { | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition( | |
addPositionHandler, | |
errorHandler, | |
{highAccuracy: false, | |
maximumAge: 30000, // 30 seconds | |
timeout: 60000 // 1 minute | |
}); | |
} | |
}; | |
function errorHandler(err) { | |
console.warn('ERROR(' + err.code + '): ' + err.message); | |
}; | |
function addPositionHandler(position) { | |
var crd = position.coords; | |
document.getElementById("lat").value = crd.latitude; | |
document.getElementById("long").value = crd.longitude; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment