如何将API密钥添加到Google Geocoding脚本

时间:2019-12-06 20:00:41

标签: google-maps google-apps-script google-sheets google-cloud-platform geocode

我要问一个与此帖子非常相似的问题:How to add my key to this google app script?

但是,该帖子的答案不再起作用(使用Maps.setAuthentication(clientId,signingKey)),因为它已用于Google Maps API Premium计划,该计划不再对新客户可用。 看到这里:https://developers.google.com/apps-script/reference/maps/maps#setAuthentication(String,String)

基本上,我正在使用以下代码来查找Google表格中10,000个地址列表的邮政编码。该代码有效,但是出现“服务在一天中被调用太多次:地址解析(第7行)”错误。我生成了一个地址解析API密钥和计费帐户,但无法确定将其插入何处。我对Google脚本代码不是很熟悉。

    function geo2zip(a) {
  var response=Maps.newGeocoder()
    .reverseGeocode(lat(a),long(a));
  return response.results[0].formatted_address.split(',')[2].trim().split(' ')[1];
}
function lat(pointa) {
 var response = Maps.newGeocoder()
     .geocode(pointa);
  return response.results[0].geometry.location.lat
}
function long(pointa) {
  var response = Maps.newGeocoder()
     .geocode(pointa);
  return response.results[0].geometry.location.lng
}

1 个答案:

答案 0 :(得分:1)

令人惊讶的是,您不能! AppScript库不是为此目的而设计的。您必须保留在允许的免费套餐中。

要使用API​​密钥,您必须调用directly the API。与您当前的版本相比没有太大变化

%02 CCCCCCC 44 3219988 EEEICEBA 3 92329193 TSETGNOL 25214321 0000