I have addresses coming in from importrange
and I am using this script to get coordinates.
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Geo 4')
var range = sheet.getDataRange();
var cells = range.getValues();
var latitudes = [];
var longitudes = [];
for (var i = 0; i < cells.length; i++) {
var address = cells[i][11];
if (address == "") {
latitudes.push([""]);
longitudes.push([""]);
} else {
var geocoder = Maps.newGeocoder().geocode(address);
var res = geocoder.results[0];
if(res){
latitudes.push([res.geometry.location.lat]);
longitudes.push([res.geometry.location.lng]);
}
else
{
latitudes.push([0]);
longitudes.push([0]);
}
}
sheet.getRange('O1').offset(0, 0, latitudes.length).setValues(latitudes)
sheet.getRange('P1').offset(0, 0, latitudes.length).setValues(longitudes);
}
}
The issue is that I have this running on a trigger every 6 hours but I need something that would get coordinates as soon as one address changes without running the whole column and using the 1000 geocodes you get per day. I have about 350 addresses constantly but maybe three change a day.