Skip to content

Instantly share code, notes, and snippets.

@nosrednawall
Created October 21, 2018 00:15
Show Gist options
  • Save nosrednawall/6a32977ce9b149d7d33eb9e002824b3d to your computer and use it in GitHub Desktop.
Save nosrednawall/6a32977ce9b149d7d33eb9e002824b3d to your computer and use it in GitHub Desktop.
Código para conseguir a longitude e a latitude de um usuário utilizando javascript
// var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var longitude = position.coords.longitude;
document.getElementById('id_longitude').value = longitude;
latitude = position.coords.latitude;
document.getElementById('id_latitude').value = latitude;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment