Category Archives: javascript

Google Location Geolocation API

Working with 3rd party data I’m finding that most of the GEO data (Latitude and Longitude) are missing or incorrect.  Thankfully the Address and City data is usually correct,

My maps display will now need to include a check for lat and lng.  If it is unavailable then I will need to call the Google Geocoding API using javascript.

 

This is the code I need to add and call from my address location function:

function codeAddress() {
    var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }