简体   繁体   中英

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

I am learning how to use Here Maps lite SDK for Android. I have pretty much copy/pasted the code in documentations to calculate a route, but am getting a weird HTTP error. Below is my code:

Start waypoint is populated using Android's location services, like this:

@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());
}

Destination is selected using com.here.sdk.search.Search like this:

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());
}

Sample values for start and destination waypoints:

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

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

This is how I am trying to calculate the route:

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);
            }
        });

I am getting an HTTP error, with the following message: 2019-12-28 16:07:22.581 32067-32171/com.example.app E/routing: [ERROR] routing - Routing error: 4, exception: Invalid routing error format, error code: 404

Has anyone ever experienced this?

UPDATE

If I call mRoutingEngine.calculateRoute() multiple times with the same parameters, eventually it succeeds and provides me with the route. That's why this behavior is baffling me

You may encounter this error if you will click only one time on the map. To get the route first click twice on the map to create start and destination waypoint and then click on add route option it will work as expected. 在此处输入图片说明

Because Routing method takes list of route as a parameter in RoutingExample.java.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM