【问题标题】:get arrival/travel time of perticular route in here-api android在here-api android中获取特定路线的到达/旅行时间
【发布时间】:2018-11-24 00:47:00
【问题描述】:

我正在使用 android Here-sdk。我从MapRoute 对象得到了特定路线的总距离。所以现在我想获得特定路线的到达/旅行时间。

下面是距离的代码。我会怎么做才能从MapRoute 对象中获取时间。谢谢!

for(int i = list_routes.size() ; i > 0 ; i--)
{
    MapRoute mapRoute = new MapRoute(list_routes.get(i-1).getRoute());
    mapRoute.setColor(color_array.get(i-1));
    mapRoute.setTrafficEnabled(true);

    // here i got total distance
    int distance = mapRoute.getRoute().getLength();

    m_map.addMapObject(mapRoute);   
} 

【问题讨论】:

    标签: android here-api


    【解决方案1】:

    你可以这样做:

    int timeInSeconds = mapRoute.getRoute().getTta(x, y).getDuration();
    

    其中xTrafficPenaltyModey 是子分支编号。详情可在documentation查看。

    【讨论】:

    • 如果我将mapRoute.getRoute().getSublegCount() 传递为y 的值throw exception of IllegalArgumentException: subleg must be >= 0 and less than the number of subleg(s)
    • 错误说明了一切。看看你在做什么。
    • @Akash 请阅读文档。有一个特殊的值WHOLE_ROUTE,你可以通过那里计算整条路线的 tta。
    【解决方案2】:

    文档链接更改使用此代替documentation

    现在不推荐使用 getTTa 方法,请使用

    Route.getTtaIncludingTraffic(int subleg)
    

    Route.getTtaExcludingTraffic(int subleg)
    

    如果您想要整个路线的行程时间,请使用此值

    Route.WHOLE_ROUTE
    

    示例:

    int timeInSeconds = route.getTtaExcludingTraffic(Route.WHOLE_ROUTE).getDuration();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多