Car and Pedestrian Routing

The Sygic Android SDK supports route calculation with multiple waypoints, optimized for walking or driving. A route describes a path between at least two waypoints, the starting point and the destination, with optional intermediate waypoints in between.
Applications can provide route information to users in two ways:

  • A line rendered on a map that displays a connecting path between all waypoints
  • Turn-by-turn directions in text format

RoutePlan is class containing all info about the route we want to calculate. It contains start, finish, viapoints and another route options.

RoutePlan routePlan = new RoutePlan();
routePlan.setStart(map.getCoordinatesFromPoint(x1, y1));
routePlan.setDestination(map.getCoordinatesFromPoint(x2, y2)); // x,y are screen coordinates

If your start and endpoint is set, you can compute your route.

Router mRouter = new Router();
mRouter.computeRoute(routePlan, mRouteComputeListener);

Now you have to add your route computing listener.

mRouteComputeListener = new RouteManager.RouteComputeListener() {
    @Override
    public void onComputeError(@RouteManager.RouteComputeError int error) {
    }

    @Override
    public void onProgress(int progress, int routeIndex) {
        // update progress
    }

    @Override
    public void onComputeStarted() {
    }

    @Override
    public void onPrimaryComputeFinished(RouteInfo route) {
        // called when primary route is calculated
    }

    @Override
    public void onAlternativeComputeFinished(RouteInfo route) {
        // called when any alternative route is calculated. Can be called more than once
    }

    @Override
    public void onComputeFinished({
        // called when all routes are calculated
    }

    @Override
    public void onRecomputeStarted() {
        // called when recompute was invoked. Recompute can be invoked after leaving computed route
    }

    @Override
    public void onRecomputeFinished(RouteInfo route) {
    }
};

Then you can set you route for navigation.

mRouter.setCurrentRoute(mRoute);  // mRoute is route obtained via onComputeFinished() method

Sygic SDK supports alternate routes between two waypoints. The alternate route feature allows more than one route to be returned after a route calculation.

The MapRoute map object

The MapRoute class is a type of MapObject that displays a calculated route on a map. Typically, an application creates a MapRoute after a route calculation, passing the relevant Route object as a parameter to the MapRoute(Route) constructor before adding the MapRoute to the map by calling Map.addMapObject(MapRoute).

For primary route:

MapRoute mapRoute = new MapRoute(routeInfo, MapRoute.RouteType.Primary); // routeInfo  is obtained via onPrimaryComputeFinished() method in RouteComputeListener
mMap.addMapObject(mapRoute);

// removing
mMap.removeMapObject(mapRoute);

For alternative route:

MapRoute mapRoute = new MapRoute(routeInfo, MapRoute.RouteType.Alternative); // routeInfo  is obtained via onAlternativeComputeFinished() method in RouteComputeListener
mMap.addMapObject(mapRoute);

// removing
mMap.removeMapObject(mapRoute);

Route Serialization