0

I have to convert longitude and latitude, into a useful address (reverse geocode), I found a good script at [Geo Scipt][1]

I am having an issue with too many requests per day, my question is how can I have this run only once (when the data is imported from ifttt) and not every time I open this google sheet?

function getLat(address) {
  if (address == '') {
    Logger.log("Must provide an address");
    return;
  }
  var geocoder = Maps.newGeocoder();
  var location;
    // Geocode the address and plug the lat, lng pair into the
    // 2nd and 3rd elements of the current range row.
    location = geocoder.geocode(address);
    // Only change cells if geocoder seems to have gotten a
    // valid response.
    if (location.status == 'OK') {
      lat = location["results"][0]["geometry"]["location"]["lat"];
 return lat;
    }
};

function getLon(address) {
  if (address == '') {
    Logger.log("Must provide an address");
    return;
  }
  var geocoder = Maps.newGeocoder();
  var location;
    // Geocode the address and plug the lat, lng pair into the
    // 2nd and 3rd elements of the current range row.
    location = geocoder.geocode(address);
    // Only change cells if geocoder seems to have gotten a
    // valid response.
    if (location.status == 'OK') {
      lng = location["results"][0]["geometry"]["location"]["lng"];
 return lng;
  }
};

function getAdd(lat, lng) {
// Return Address by taking the coordinates and reverse geocoding.
if (lat == "") {
return "You have to provide latitudinal coordinates to the place"
} if (lng == ""){
return "You have to provide longitudinal coordinates to the place"
}

var response = Maps.newGeocoder().reverseGeocode(lat, lng); //Call the reverse Geocode service
for (var i = 0; i < response.results.length; i++) {
var result = response.results[i];

return result.formatted_address; //Output full address in cell
Utilities.sleep(Math.random() * 500);
  }
};
Rubén
  • 34,714
  • 9
  • 70
  • 166
exilepc
  • 33
  • 4
  • How do you run these functions now? They aren't running themselves. –  Jun 11 '16 at 09:08

1 Answers1

1

The Service invoked too many times for one day indicates that the given service exceed the total allowable execution time for one day. It most commonly occurs for scripts that run on a trigger, which have a lower daily limit than scripts executed manually. Instead of Google Sheet, try to use Fusion Tables

Each time a custom function is used in a spreadsheet, Google Sheets makes a separate call to the Apps Script server. If your spreadsheet contains dozens (or hundreds, or thousands!) of custom function calls, this process can be quite slow. It could be helpful to read Map your data with the Maps API and Fusion Table

If a script reaches a quota or limitation, it will throw an exception with a message, for more information regarding this, follow this link: https://developers.google.com/apps-script/guides/services/quotas#current_limitations

Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30