尝试使用 HERE Maps Android Lite API 计算路线时出现 HTTP 错误

HTTP Error while trying to calculate a route using HERE Maps Android Lite API

我正在学习如何使用 Android 的 Here Maps lite SDK。我在文档中有很多 copy/pasted 计算路由的代码,但我收到了一个奇怪的 HTTP 错误。下面是我的代码:

使用 Android 的定位服务填充起始航路点,如下所示:

@Override
public void onCreate(Bundle savedInstanceState) {
    // ... other initialization code handling permissions and what else
    mLocationManager = (LocationManager) Objects.requireNonNull(getActivity()).getSystemService(Context.LOCATION_SERVICE);
    if (mLocationManager != null) {
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5, 5, this);
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5, 5, this);
    }
}

@Override
public void onLocationChanged(Location location) {
    startWaypoint = new GeoCoordinates(location.getLatitude(), location.getLongitude());
}

目的地是使用 com.here.sdk.search.Search 选择的,如下所示:

try {
    searchEngine = new SearchEngine();

    int maxSearchResults = 30;
    SearchOptions searchOptions = new SearchOptions(
            LanguageCode.EN_GB,
            TextFormat.PLAIN,
            maxSearchResults);
    searchEngine.search(startWaypoint, 'Westfield', searchOptions, (searchError, list) -> {
        MyApplication.getsInstance().hideProgress();
        if (searchError != null) {
            return;
        }
        destinationWaypoint  = list.get(0).coordinates;
    });
} catch (InstantiationErrorException e) {
    new RuntimeException("Initialization of SearchEngine failed: " + e.error.name());
}

起点和终点的样本值 waypoints:

startWaypoint {
    Lat: -33.79073353
    Lon: 150.99847916
    Alt: null
}

destinationWaypoint {
    Lat: -33.81746
    Lon: 151.00357
    Alt: null
}

这是我尝试计算路线的方式:

List<Waypoint> waypoints = new ArrayList<>(Arrays.asList(startWaypoint, destinationWaypoint));

mRoutingEngine.calculateRoute(
        waypoints,
        new RoutingEngine.CarOptions(),
        (routingError, routes) -> {
            if (routingError == null) {
                if ((routes != null) && (routes.size() > 0)) {
                    Route route = routes.get(0);
                    showRouteDetails(route);
                    showRouteOnMap(route);
                    zoomToRoute(route);
                } else {
                    MyApplication.getsInstance().showDialog(getActivity(), false, "Error while calculating a route:", "Could not calculate a route", "OK", null, null, null);
                }
            } else {
                MyApplication.getsInstance().showDialog(getActivity(), false, "Error while calculating a route:", routingError.toString(), "OK", null, null, null);
            }
        });

我收到 HTTP 错误,消息如下: 2019-12-28 16:07:22.581 32067-32171/com.example.app E/routing: [ERROR] 路由 - 路由错误:4,异常:路由错误格式无效,错误代码:404

有没有人遇到过这种情况?

更新

如果我使用相同的参数多次调用 mRoutingEngine.calculateRoute(),最终它会成功并为我提供路线。这就是为什么这种行为让我感到困惑

如果您只在地图上单击一次,您可能会遇到此错误。要获取路线,请先在地图上单击两次以创建起点和目的地航路点,然后单击添加路线选项,它将按预期工作。

因为路由方法在RoutingExample.java中将路由列表作为参数。

希望对您有所帮助。