Last active
August 29, 2015 14:07
-
-
Save valdiney/02f0f8def80dee9d0645 to your computer and use it in GitHub Desktop.
Pegando Latitude e longetude com a API do google...
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
<!DOCTYPE> | |
<html> | |
<head> | |
<title>Pegar Latitude e Longitude por endereço</title> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
</head> | |
<body> | |
<form> | |
<label>Rua/Av : | |
<input type="text-box" id="endereco"> | |
</label> | |
<label>Bairro : | |
<input type="text-box" id="bairro"> | |
</label> | |
<label>Cidade : | |
<input type="text-box" id="cidade"> | |
</label> | |
<label>Latidude | |
<input type="text-box" id="latitude"> | |
</label> | |
<label>Longitude : | |
<input type="text-box" id="longitude"> | |
</label> | |
<button type="button" id="executar">Pegar</button> | |
</form> | |
<script> | |
///////////////////////////////////////////////////////////// | |
/* Pegando Latitude e longetude com a API do google... */ | |
//////////////////////////////////////////////////////////// | |
window.onload = function() { | |
var pegarLatitudeELongitude = function() { | |
var geocoder = new google.maps.Geocoder(), | |
address = document.querySelector("#endereco").value, | |
bairro = document.querySelector("#bairro").value, | |
cidade = document.querySelector("#cidade").value, | |
latitude = document.querySelector("#latitude"), | |
longitude = document.querySelector("#longitude"); | |
geocoder.geocode({ | |
'address': address | |
}, function(results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
latitude.value = results[0].geometry.location.lat(); | |
longitude.value = results[0].geometry.location.lng(); | |
}; | |
}); | |
}; | |
var buscar = document.querySelector("#executar"); | |
buscar.addEventListener("click", function() { | |
pegarLatitudeELongitude(); | |
}); | |
}; //... | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment