Convert ZIP to latitude and longitude (Javascript)

2

I need a Javascript api that converts a ZIP code typed into latitude and longitude, does anyone know one I can use for free?

    
asked by anonymous 24.05.2016 / 16:11

1 answer

7

You can use Google's geocoding . Home Add the Google API

<script src="http://maps.google.com/maps/api/js"></script>

Thenjustpasstheziporaddresstogetthelatitudeandlongitude

varlat='';varlng='';varaddress={cep}or{endereço};geocoder.geocode({'address':address},function(results,status){if(status==google.maps.GeocoderStatus.OK){lat=results[0].geometry.location.lat();lng=results[0].geometry.location.lng();}else{alert("Não foi possivel obter localização: " + status);
  }
});
alert('Latitude: ' + lat + ' Logitude: ' + lng);
    
24.05.2016 / 18:41