0

I have the following code below that geocodes address from a google spreadsheet. I have research this but I can't find a good example of how to just geocode postal codes in the US. Does anyone know a good example. Thanks

    function geocode(address) {
      var response = UrlFetchApp.fetch("http://maps.googleapis.com/maps/api/geocode/json?address="+escape(address)+"&sensor=false");

      var respObj=Utilities.jsonParse(response.getContentText());
      var loc = {lat:NaN,lng:NaN};
          try {
          loc = respObj.results[0].geometry.ZIP_CODE
          } catch(e) {
          Logger.log("Error geocoding: "+address);
          }
      return loc;
}
Piyush
  • 1,973
  • 1
  • 19
  • 30
user30832
  • 71
  • 1
  • 3

1 Answers1

0

https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple?csw=1

Try putting in a zip code it works.

This is the relevant code

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);
     }
   });
}
Eric Guan
  • 15,474
  • 8
  • 50
  • 61