Skip to content

Instantly share code, notes, and snippets.

@valdiney
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valdiney/02f0f8def80dee9d0645 to your computer and use it in GitHub Desktop.
Save valdiney/02f0f8def80dee9d0645 to your computer and use it in GitHub Desktop.
Pegando Latitude e longetude com a API do google...
<!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