Search in sources :

Example 1 with OnlineRoutingResponse

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine.OnlineRoutingResponse in project Osmand by osmandapp.

the class RouteProvider method findOnlineRoute.

private RouteCalculationResult findOnlineRoute(RouteCalculationParams params) throws IOException, JSONException {
    OsmandApplication app = params.ctx;
    OnlineRoutingHelper helper = app.getOnlineRoutingHelper();
    OsmandSettings settings = app.getSettings();
    String engineKey = params.mode.getRoutingProfile();
    OnlineRoutingResponse response = helper.calculateRouteOnline(engineKey, getPathFromParams(params), params.start.hasBearing() ? params.start.getBearing() : null, params.leftSide, params.initialCalculation);
    if (response != null) {
        if (response.getGpxFile() != null) {
            GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(response.getGpxFile(), settings);
            builder.setCalculatedRouteTimeSpeed(response.hasCalculatedTimeSpeed());
            params.gpxRoute = builder.build(app);
            return calculateGpxRoute(params);
        }
        List<Location> route = response.getRoute();
        List<RouteDirectionInfo> directions = response.getDirections();
        if (!Algorithms.isEmpty(route) && !Algorithms.isEmpty(directions)) {
            params.intermediates = null;
            return new RouteCalculationResult(route, directions, params, null, false);
        }
    } else {
        params.initialCalculation = false;
    }
    return new RouteCalculationResult("Route is empty");
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) OnlineRoutingHelper(net.osmand.plus.onlinerouting.OnlineRoutingHelper) OnlineRoutingResponse(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine.OnlineRoutingResponse) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) Location(net.osmand.Location)

Example 2 with OnlineRoutingResponse

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine.OnlineRoutingResponse in project Osmand by osmandapp.

the class MissingMapsHelper method findOnlineRoutePoints.

public List<Location> findOnlineRoutePoints() throws IOException, JSONException {
    List<LatLon> points = new ArrayList<>();
    List<Location> routeLocation = new ArrayList<>();
    OnlineRoutingHelper onlineRoutingHelper = params.ctx.getOnlineRoutingHelper();
    List<Location> location = getStartFinishIntermediatePoints();
    for (Location e : location) {
        points.add(new LatLon(e.getLatitude(), e.getLongitude()));
    }
    OnlineRoutingEngine engine = onlineRoutingHelper.startOsrmEngine(params.mode);
    if (engine != null) {
        OnlineRoutingResponse response = onlineRoutingHelper.calculateRouteOnline(engine, points, params.start.hasBearing() ? params.start.getBearing() : null, params.leftSide, false);
        if (response != null) {
            routeLocation.addAll(response.getRoute());
        }
    }
    return removeDensePoints(routeLocation);
}
Also used : LatLon(net.osmand.data.LatLon) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) ArrayList(java.util.ArrayList) OnlineRoutingHelper(net.osmand.plus.onlinerouting.OnlineRoutingHelper) OnlineRoutingResponse(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine.OnlineRoutingResponse) Location(net.osmand.Location)

Aggregations

Location (net.osmand.Location)2 OnlineRoutingHelper (net.osmand.plus.onlinerouting.OnlineRoutingHelper)2 OnlineRoutingResponse (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine.OnlineRoutingResponse)2 ArrayList (java.util.ArrayList)1 LatLon (net.osmand.data.LatLon)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)1 GPXRouteParamsBuilder (net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder)1 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)1