Skip to content

Instantly share code, notes, and snippets.

@Superbil
Last active September 7, 2016 15:46
Show Gist options
  • Save Superbil/d0b73d05d0581fc9e1271551d4e88763 to your computer and use it in GitHub Desktop.
Save Superbil/d0b73d05d0581fc9e1271551d4e88763 to your computer and use it in GitHub Desktop.
lat and lng can't set, because is null
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);
};
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