Reputation: 357
I have a field called ADDRESS on my webpage. I also have a field called COORDINATES on my webpage. Can someone give me specific JQUERY or JAVASCRIPT code to take the address in ADDRESS and have lattitude and longitude coordinates show up in COORDINATES field.
EXAMPLE
ADDRESS - 1 MetLife Stadium Dr, East Rutherford, NJ 07073
COORDINATES - 40.814209 / -74.073690
Please give a specific example. I know i might need an API key or something. I tried looking at google maps API documentation, but it was a bit confusing. Thank You.
Upvotes: 1
Views: 8743
Reputation: 1465
Try this!
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
var address = jQuery('#address').val();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
jQuery('#coordinates').val(latitude+', '+longitude);
}
});
</script>
Upvotes: 6