默认为Google Directions API的当前时间的语法

时间:2014-07-28 20:04:29

标签: json google-maps parsing google-direction

我正在尝试解析此网址,并且我想知道是否有人可以告诉我要为departure_time参数添加什么内容以使其默认为当前时间:

https://maps.googleapis.com/maps/api/directions/json?origin=25broadyway&destination=pennstation,ny&departure_time=????current&mode=transit

我试过了: current,0,time.now ....我无法弄清楚

2 个答案:

答案 0 :(得分:0)

来自Google API:https://developers.google.com/maps/documentation/directions/

departure_time 指定所需的出发时间为自UTC 1970年1月1日午夜起的秒* 。 示例:http://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&key= {API_KEY}& departure_time = 1343641500& mode = transit

编辑: 尝试类似这种方法的东西,以便在几秒钟内获得 departure_time

private static string GoogleMapsDepartureTime(DateTime localTime)
{
    DateTime inceptionDateTime = DateTime.Parse("01/01/1970 00:00:00");
    DateTime departureDateTime = localTime.ToUniversalTime();
    TimeSpan departureTimeSpan = departureDateTime - inceptionDateTime;
    double departureTimeSeconds = departureTimeSpan.TotalSeconds;

    return departureTimeSeconds.ToString().Split('.')[0];   
}

答案 1 :(得分:0)

我注意到没有接受的答案或反馈,所以我会对它采取一些措施。你应该写“现在”,它会给你离开最近的秒的出发时间。

来源: https://developers.google.com/maps/documentation/directions/