【发布时间】:2018-08-28 14:21:41
【问题描述】:
我正在尝试从绑定到 Google 表单的脚本访问地图。我遇到的问题是,在调试脚本时,它经常访问地图,以至于我遇到了配额限制。我有一个 Maps API 密钥,但没有客户端 ID,因此无法让 Maps.setAuthenication(clientID,Key) 工作。我这样做是为了侦察部队,所以不想付费访问地图。
谁能帮忙?
随后我被要求发布我的代码,所以这里是:
function setLocation(){
var whereString;
var theDuration;
var theDistance;
var theRoute;
var theDirections;
var theTravelString;
// this Sets the Where: Tab on the form
whereString = 'Where: ' + gLocation;
theItemArray = gSignupForm.getItems();
theItemArray[kWhereItem].setTitle(whereString);
//this gets the directions to the location
Maps.setAuthentication('','ABCDEFGHIJKLMNOP');
//Obviously Im'm not going to post the true key
theDirections = Maps.newDirectionFinder()
.setOrigin('7101 Shadeland Ave, Indianapolis, IN 46256')
.setDestination(gLocation)
.setMode(Maps.DirectionFinder.Mode.DRIVING)
.getDirections();
theRoute = theDirections.routes[0];
theDuration = theRoute.legs[0].duration.text;
theDistance = theRoute.legs[0].distance.text;
theTravelString = Utilities.formatString('Travel Considerations: The estimated travel distance is %u miles. ',theDistance);
theTravelString += 'The estimated travel time is ' + theDuration;
theItemArray[kTravelItem].setTitle(theTravelString);
}
【问题讨论】:
-
请分享您的代码并解释您想要实现的目标以及预期的结果。另外,请阅读“如何提问”stackoverflow.com/help/how-to-ask
-
考虑使用 CacheService 以避免重复重新查询相同的信息。 IE。从给定的起点-终点对生成数据后,将其存储在缓存中长达 6 小时。然后在此处修改给定的位,以便在查询 Maps 之前先检查缓存。
-
根据 doc,除非您拥有 Maps API for Business 帐户,否则您将无法使用
setAuthentication。