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.
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.
Share Improve this question asked Jan 12, 2016 at 5:54 Maria NolorbeMaria Nolorbe 3571 gold badge4 silver badges14 bronze badges 1- 1 This is called reverse geocoding and the google maps geocode API has all the information you need to do this. Finding examples is not hard – charlietfl Commented Jan 12, 2016 at 6:11
1 Answer
Reset to default 6Try this!
<script type="text/javascript" src="http://maps.google./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>