Skip to content

Instantly share code, notes, and snippets.

@fabiocarneiro
Last active August 29, 2015 14:10
Show Gist options
  • Save fabiocarneiro/d2beb59fa4146f989ffd to your computer and use it in GitHub Desktop.
Save fabiocarneiro/d2beb59fa4146f989ffd to your computer and use it in GitHub Desktop.
<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