Last active
August 29, 2015 14:10
-
-
Save fabiocarneiro/d2beb59fa4146f989ffd to your computer and use it in GitHub Desktop.
This file contains 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
<script> | |
function retrieveUf(latitude,longitude){ | |
var request = new XMLHttpRequest(); | |
var method = 'GET'; | |
var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+latitude+','+longitude+'&sensor=true'; | |
var async = true; | |
request.open(method, url, async); | |
request.send(); | |
}; | |
var successCallback = function(position){ | |
var x = position.coords.latitude; | |
var y = position.coords.longitude; | |
console.log(position.coords); | |
}; | |
var errorCallback = function(error){ | |
var errorMessage = 'Erro desconhecido.'; | |
switch(error.code) { | |
case 1: | |
errorMessage = 'Permissão negada.'; | |
break; | |
case 2: | |
errorMessage = 'Posição indisponível.'; | |
break; | |
case 3: | |
errorMessage = 'Tempo esgotado.'; | |
break; | |
} | |
alert(errorMessage); | |
}; | |
var options = { | |
enableHighAccuracy: true, | |
timeout: 1000, | |
maximumAge: 0 | |
}; | |
navigator.geolocation.getCurrentPosition(successCallback,errorCallback,options); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment