主要的需求是找到两个地点或邮政编码之间的交通数据的旅行时间。
输入参数将来自位置、目的地、到达时间(这是在早上6点和8点之间)、交通方式、交通模型
根据我的google脚本函数中的上述输入参数,它应该返回旅行时间
下面的代码可以针对这个需求进行修改吗?
function GetDuration(location1, location2, mode) {
var directions = Maps.newDirectionFinder()
.setOrigin(location1)
.setDestination(location2)
.setMode(Maps.DirectionFinder.Mode[mode])
.getDirections();
return directions.routes[0].legs[0].duration.text;
}
//directions from Times Sq to Central Park, NY
Logger.log(GetDuration("40.7591017,-73.984488","40.7670973,-73.9793693","DRIVING") )
From To Mode Distance
Central Park, NY Times Sq TRANSIT 8 mins发布于 2019-09-06 15:52:03
请在下面找到如何使用setArrive()的示例
function GetDuration(location1, location2, mode) {
var arrive = new Date(new Date().getTime() + (10 * 60 * 60 * 1000));//arrive in ten hours from now
var directions = Maps.newDirectionFinder().setArrive(arrive)
.setOrigin(location1)
.setDestination(location2)
.setMode(Maps.DirectionFinder.Mode[mode])
.getDirections();
return directions.routes[0].legs[0].duration.text;
}如果您想要提供到达时间-您还需要指定日期-就像在Google Maps的用户界面中一样。可以使用JavaScript date methods创建日期。
例如,使用new Date(year, month, day, hours, minutes, seconds, milliseconds)。
示例:
var arrive=new Date(2019, 09, 07, 06);// 7th of September 2019 06:00 amhttps://stackoverflow.com/questions/57810486
复制相似问题