首页 > 解决方案 > Here API:使用 Android sdk 获取错误的公交路线信息

问题描述

我尝试使用 Android sdk 获取基本的运输路线,但我缺少我需要的数据。

基本上,我想获得与 Here We Go 规划器完全相同的数据。您可以在哪里看到这些步骤、它们的出发和到达时间、哪种交通方式以及出发或到达的平台。

因此,当我尝试在 Android sdk 中使用 RoutePlan 时,它给了我一个错误的 tta,到目前为止,如果没有任何额外的步骤,我可以看到它比它应该长的一个小时。它也没有显示平台和步骤的出发/到达时间。这同样适用于向 Postman 中的路由 api 发送路由请求。

我的问题是,如何使用 Android sdk 检索与 Here We Go 计划器和应用程序完全相同的数据?

更新:我的 Here 项目页面还为我的大多数请求显示“估计的公共交通”,这是应该的还是应该是其他的?

更新 2:我尝试使用 here we go maps 1、 postman [下面的代码] 和 android sdk [下面的代码] 用于相同的路线,并得到了非常不同的结果。

邮递员请求:https: //route.api.here.com/routing/7.2/calculateroute.json?app_id= app_id &app_code= app_code &waypoint0=52.3146653,5.0248838&waypoint1=52.6381,4.7405999999999972&departure=now&mode=fastest;publicTransport&combineChange=true

结果:

{
"response": {
    "metaInfo": {
        "timestamp": "2019-06-18T07:59:29Z",
        "mapVersion": "8.30.97.151",
        "moduleVersion": "7.2.201923-3839",
        "interfaceVersion": "2.6.58",
        "availableMapVersion": [
            "8.30.97.151"
        ]
    },
    "route": [
        {
            "waypoint": [
                {
                    "linkId": "-54239714",
                    "mappedPosition": {
                        "latitude": 52.3146951,
                        "longitude": 5.0248396
                    },
                    "originalPosition": {
                        "latitude": 52.3146653,
                        "longitude": 5.0248837
                    },
                    "type": "stopOver",
                    "spot": 1,
                    "sideOfStreet": "left",
                    "mappedRoadName": "Pampuslaan",
                    "label": "Pampuslaan",
                    "shapeIndex": 0,
                    "source": "user"
                },
                {
                    "linkId": "-1208098680",
                    "mappedPosition": {
                        "latitude": 52.6384828,
                        "longitude": 4.740455
                    },
                    "originalPosition": {
                        "latitude": 52.6381,
                        "longitude": 4.7406
                    },
                    "type": "stopOver",
                    "spot": 0.247191,
                    "sideOfStreet": "left",
                    "mappedRoadName": "Kruseman van Eltenweg",
                    "label": "Kruseman van Eltenweg",
                    "shapeIndex": 288,
                    "source": "user"
                }
            ],
            "mode": {
                "type": "fastest",
                "transportModes": [
                    "publicTransport"
                ],
                "trafficMode": "disabled",
                "feature": []
            },
            "leg": [
                {
                    "start": {
                        "linkId": "-54239714",
                        "mappedPosition": {
                            "latitude": 52.3146951,
                            "longitude": 5.0248396
                        },
                        "originalPosition": {
                            "latitude": 52.3146653,
                            "longitude": 5.0248837
                        },
                        "type": "stopOver",
                        "spot": 1,
                        "sideOfStreet": "left",
                        "mappedRoadName": "Pampuslaan",
                        "label": "Pampuslaan",
                        "shapeIndex": 0,
                        "source": "user"
                    },
                    "end": {
                        "linkId": "-1208098680",
                        "mappedPosition": {
                            "latitude": 52.6384828,
                            "longitude": 4.740455
                        },
                        "originalPosition": {
                            "latitude": 52.6381,
                            "longitude": 4.7406
                        },
                        "type": "stopOver",
                        "spot": 0.247191,
                        "sideOfStreet": "left",
                        "mappedRoadName": "Kruseman van Eltenweg",
                        "label": "Kruseman van Eltenweg",
                        "shapeIndex": 288,
                        "source": "user"
                    },
                    "length": 57000,
                    "travelTime": 7637,
                    "maneuver": [
                        {
                            "position": {
                                "latitude": 52.3146951,
                                "longitude": 5.0248396
                            },
                            "instruction": "Head <span class=\"heading\">south</span> on <span class=\"street\">Pampuslaan</span>. <span class=\"distance-description\">Go for <span class=\"length\">99 m</span>.</span>",
                            "travelTime": 109,
                            "length": 99,
                            "id": "M1",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.3138046,
                                "longitude": 5.024904
                            },
                            "instruction": "Turn <span class=\"direction\">left</span> onto <span class=\"next-street\">Gemeenschapspolderweg</span>. <span class=\"distance-description\">Go for <span class=\"length\">887 m</span>.</span>",
                            "travelTime": 912,
                            "length": 887,
                            "id": "M2",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.3131716,
                                "longitude": 5.0369418
                            },
                            "instruction": "Turn <span class=\"direction\">left</span> onto <span class=\"next-street\">Jan Campertplein</span>. <span class=\"distance-description\">Go for <span class=\"length\">98 m</span>.</span>",
                            "travelTime": 110,
                            "length": 98,
                            "id": "M3",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.3137081,
                                "longitude": 5.0380576
                            },
                            "instruction": "Turn <span class=\"direction\">right</span> onto <span class=\"next-street\">E. du Perronstraat</span>. <span class=\"distance-description\">Go for <span class=\"length\">338 m</span>.</span>",
                            "travelTime": 349,
                            "length": 338,
                            "id": "M4",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.3127103,
                                "longitude": 5.0419629
                            },
                            "instruction": "Turn <span class=\"direction\">right</span> onto <span class=\"next-street\">Stationsplein</span>. <span class=\"distance-description\">Go for <span class=\"length\">21 m</span>.</span>",
                            "travelTime": 32,
                            "length": 21,
                            "id": "M5",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.3125601,
                                "longitude": 5.0421453
                            },
                            "instruction": "Turn <span class=\"direction\">left</span>. <span class=\"distance-description\">Go for <span class=\"length\">133 m</span>.</span>",
                            "travelTime": 133,
                            "length": 133,
                            "id": "M6",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.312485,
                                "longitude": 5.0435722
                            },
                            "instruction": "Go to the station <span class=\"station\">Weesp</span> and take the <span class=\"transit\">train</span> <span class=\"line\">Sprinter</span> toward <span class=\"destination\">Amsterdam Centraal</span>. <span class=\"distance-description\">Follow for <span class=\"stops\">4 stations</span>.</span>",
                            "travelTime": 1915,
                            "length": 13021,
                            "id": "M7",
                            "stopName": "Weesp",
                            "_type": "PublicTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.3787248,
                                "longitude": 4.9008143
                            },
                            "instruction": "Get off at <span class=\"station\">Amsterdam Centraal</span> and change to the <span class=\"transit\">train</span> <span class=\"line\">Intercity</span> toward <span class=\"destination\">Alkmaar</span>. <span class=\"distance-description\">Follow for <span class=\"stops\">4 stations</span>.</span>",
                            "travelTime": 3095,
                            "length": 41444,
                            "id": "M8",
                            "stopName": "Amsterdam Centraal",
                            "_type": "PublicTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.6377726,
                                "longitude": 4.7408044
                            },
                            "instruction": "Get off at <span class=\"station\">Alkmaar</span>.",
                            "travelTime": 0,
                            "length": 0,
                            "id": "M9",
                            "stopName": "Alkmaar",
                            "_type": "PublicTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.6377726,
                                "longitude": 4.7408044
                            },
                            "instruction": "Head <span class=\"heading\">southeast</span>. <span class=\"distance-description\">Go for <span class=\"length\">367 m</span>.</span>",
                            "travelTime": 378,
                            "length": 367,
                            "id": "M10",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.637794,
                                "longitude": 4.7458577
                            },
                            "instruction": "Turn <span class=\"direction\">left</span> onto <span class=\"next-street\">Helderseweg</span>. <span class=\"distance-description\">Go for <span class=\"length\">208 m</span>.</span>",
                            "travelTime": 217,
                            "length": 208,
                            "id": "M11",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.6396501,
                                "longitude": 4.7454929
                            },
                            "instruction": "Turn <span class=\"direction\">left</span> onto <span class=\"next-street\">Kruseman van Eltenweg</span>. <span class=\"distance-description\">Go for <span class=\"length\">384 m</span>.</span>",
                            "travelTime": 387,
                            "length": 384,
                            "id": "M12",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 52.6384828,
                                "longitude": 4.740455
                            },
                            "instruction": "Arrive at <span class=\"street\">Kruseman van Eltenweg</span>. Your destination is on the left.",
                            "travelTime": 0,
                            "length": 0,
                            "id": "M13",
                            "_type": "PrivateTransportManeuverType"
                        }
                    ]
                }
            ],
            "publicTransportLine": [
                {
                    "lineName": "Sprinter",
                    "companyName": "",
                    "destination": "Amsterdam Centraal",
                    "type": "trainRegional",
                    "id": "L1"
                },
                {
                    "lineName": "Intercity",
                    "companyName": "",
                    "destination": "Alkmaar",
                    "type": "trainRegional",
                    "id": "L2"
                }
            ],
            "summary": {
                "distance": 57000,
                "baseTime": 7637,
                "flags": [
                    "noThroughRoad",
                    "builtUpArea",
                    "privateRoad"
                ],
                "text": "The trip takes <span class=\"length\">57.0 km</span> and <span class=\"time\">2:07 h</span>.",
                "travelTime": 7637,
                "departure": "2019-06-18T09:59:29+02:00",
                "_type": "PublicTransportRouteSummaryType"
            }
        }
    ],
    "language": "en-us"
}

}

在 Android 中记录路线的出发时间和持续时间导致: I/Departure time: 10:00 I/Duration: 02:51

使用以下代码片段: 计划:

       RoutePlan routePlan = new RoutePlan();

    RouteOptions routeOptions = new RouteOptions();
    routeOptions.setTransportMode(RouteOptions.TransportMode.PUBLIC_TRANSPORT);
    routeOptions.setRouteType(RouteOptions.Type.FASTEST);
    routeOptions.setRouteCount(3);
    routeOptions.setLocale(Locale.getDefault());
    if (toggleSwitch.getCheckedTogglePosition() == 0) {
        routeOptions.setTime(selected_time, RouteOptions.TimeType.DEPARTURE);
    }
    else {
        // Arrival time
    }
    routePlan.setRouteOptions(routeOptions);

    // Select Waypoints for your routes
    routePlan.addWaypoint(new RouteWaypoint(start_address_coordinate));
    routePlan.addWaypoint(new RouteWaypoint(end_address_coordinate));
    router.calculateRoute(routePlan, new RouterListener());

结果监听器:

  private final class RouterListener implements CoreRouter.Listener {

    // Method defined in Listener
    public void onProgress(int percentage) {
        // Display a message indicating calculation progress
    }

    // Method defined in Listener
    public void onCalculateRouteFinished(List<RouteResult> routeResult, RoutingError error) {
        // If the route was calculated successfully
        if (error == RoutingError.NONE) {
            progressBar.setVisibility(View.GONE);
            planButton.setEnabled(true);

            Long start_time = routeResult.get(0).getRoute().getManeuvers().get(0).getStartTime().getTime();
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.getDefault());
            String start_date = sdf.format(new Date(start_time));

            Date duration = new Date(routeResult.get(0).getRoute().getTtaIncludingTraffic(Route.WHOLE_ROUTE).getDuration() * 1000);

            Log.i("Departure time", start_date);
            Log.i("Duration", sdf.format(duration));
        }
        else {
            // Display a message indicating route calculation failure
            Log.e("Route Calculation ERROR", error.toString());
        }
    }
}

标签: here-api

解决方案


根据HERE Routing API 的 PT文档:

Routing API 以两种方式之一计算公共交通路线:

  • 估计路线——使用聚合数据来估计路线。
  • 时间表路线 – 使用动态数据提供更精确、更详细的路线。

您可以在http://refclient.ext.here.com/上玩以上两者的尊重吗?

根据Android mSDK的文档,您可以使用已知的在线时间表信息计算过境路线,但此功能 SDK-Route-PT-Timetable未为 Freemium 帐户启用(尚未在文档中,对此感到抱歉),因此对于 Freemium 凭证将使用 Estimated Routing(不是 Timetable Routing),结果将与 Routing API Estimated Routing for Public Transport 的结果相对应。(记住 Routing API 请设置出发时间参数,否则默认使用 TimeTable 进行计算)

如果您想在您的 mSDK 中拥有 SDK-Route-PT-Timetable 功能,请联系我们以获取更多详细信息:

服务支持

联系这里


推荐阅读