我必须将经度和纬度转换为有用的地址(反向地理编码),我在[Geo Scipt]找到了一个好的脚本[1]
我遇到每天请求过多的问题,我的问题是如何才能运行一次(从ifttt导入数据时)而不是每次打开这个google工作表?
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);
}
};
答案 0 :(得分:0)
Service invoked too many times for one day
表示给定服务超过一天允许的总执行时间。最常见的是在触发器上运行的脚本,其每日限制低于手动执行的脚本。请尝试use Fusion Tables
每次在电子表格中使用自定义功能时,Google表格都会单独调用Apps脚本服务器。如果您的电子表格包含数十(或数百,或数千!)个自定义函数调用,则此过程可能会非常慢。使用Maps API and Fusion Table
阅读地图数据可能会有所帮助如果脚本达到配额或限制,它将抛出包含消息的异常,有关此消息的更多信息,请点击以下链接:https://developers.google.com/apps-script/guides/services/quotas#current_limitations