【发布时间】:2019-06-13 12:43:07
【问题描述】:
我需要更新这个脚本来传递我的密钥,这样我就不会超过每天的限制。我将如何修改此脚本以传递我的密钥?
(注意:此处可找到 google 课程信息:https://developers.google.com/apps-script/reference/maps/geocoder)
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
}
我以前从未使用过谷歌应用程序脚本。
我有这个脚本,并且正在使用“=geo2zip(cell)”从我的谷歌表中调用脚本来获取不完整地址的邮政编码。我的工作表中有〜28k。我已经在我的谷歌控制台和我的账单信息中启用了地理编码 API。并创建了我的密钥,但不确定如何在上面的脚本中包含我的密钥。
我也尝试过使用以下方法来使用我的密钥调用 api。它正在工作,但这导致响应非常缓慢。按照这些回复的速度,我需要 10 天才能完成更新我的 28k 条记录。
CELL M4852--> "https://maps.googleapis.com/maps/api/geocode/xml?address=ADDRESS&key=MYKEY" 下一个单元格--> "=ImportXML(M4852,"/GeocodeResponse/result/formatted_address")"
脚本的响应速度更快,所以我更愿意使用它并传递我的密钥。如果您能提供帮助,请告诉我。
更新:我能够使用 Alberto 在下面添加 Maps.setAuthentication 的建议解决此问题。
【问题讨论】:
-
欢迎来到stackoverflow。请描述您尝试了什么以及您在哪里卡住了。另请参阅How do I ask a good question?上的此文档
-
谢谢@Gustavo 我已经更新了我上面的问题以提供更多信息。
标签: google-apps-script key reverse-geocoding google-geocoding-api