Document Navigation SDK for Android Guides Route Planning Cycling and Walking Routing

Cycling and Walking Routing

The Navigation SDK provides route planning and navigation capabilities for both cycling and walking scenarios. It applies scenario-specific algorithm optimizations tailored to the characteristics of cycling and walking, producing more reasonable and convenient routes, and delivering clearer voice prompts and navigation feedback.

To implement cycling and walking route planning, you need to understand the following two classes:

AMapNavi: This is the navigation management class. It provides methods for route planning, pre-trip route selection, and rerouting during navigation. It is a singleton; obtain the instance via getInstance() and destroy it via destroy().

AMapNaviListener: This is the protocol interface for navigation events and data. It provides callbacks for events during route calculation and navigation (such as route planning success/failure, TTS strings, weak GPS signal, arrival at destination, etc.) and real-time data (such as guidance information NaviInfo, location data, electronic eye information, etc.).

Important Notes

Note: Route planning requires a network connection.

* Origin and destination information can be obtained in several ways, such as using the coordinate picker to find coordinates for a point, or using the POI search feature in the Search SDK to find points of interest to use as origins or destinations.

* Cycling and walking route calculation supports both single-route and multi-route planning. You can specify the TravelStrategy enum in the POI route calculation interface.

Strategy Enum

Value

Description

TravelStrategy.SINGLE

1000

Single route planning for cycling/walking.

TravelStrategy.MULTIPLE

1001

Multi-route planning for cycling/walking (not all routes support multi-route planning).

1. Route Planning by Coordinates

Plan a route by providing the latitude and longitude coordinates of the origin and destination.

Cycling Route Calculation

// Origin information
NaviLatLng start = new NaviLatLng(39.993308, 116.473199);
// Destination information
NaviLatLng end = new NaviLatLng(39.917834, 116.397036);
// Calculate cycling route by coordinates
AMapNavi.getInstance(this).calculateRideRoute(start, end);

Walking Route Calculation

// Origin information
NaviLatLng start = new NaviLatLng(39.993308, 116.473199);
// Destination information
NaviLatLng end = new NaviLatLng(39.917834, 116.397036);
// Calculate walking route by coordinates
AMapNavi.getInstance(this).calculateWalkRoute(start, end);

2. Route Planning by POI

Plan a cycling or walking route by providing the POI information of the origin and destination.

2.1 Single Route Planning

// Construct origin POI
NaviPoi start = new NaviPoi("The Palace Museum", null, "B000A8UIN8");
// Construct destination POI
NaviPoi end = new NaviPoi("Peking University", null, "B000A816R6");
// Calculate cycling route
AMapNavi.getInstance(this).calculateRideRoute(start, end, TravelStrategy.SINGLE);

2.2 Multi-Route Planning

// Construct origin POI
NaviPoi start = new NaviPoi("The Palace Museum", null, "B000A8UIN8");
// Construct destination POI
NaviPoi end = new NaviPoi("Peking University", null, "B000A816R6");
// Calculate walking route
AMapNavi.getInstance(this).calculateWalkRoute(start, end, TravelStrategy.MULTIPLE);

3. Handling Results

When route planning is successful, the onCalculateRouteSuccess callback of AMapNaviListener is triggered. Within this callback, you can retrieve the route object and display the planned route:

@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult routeResult) {
    // Get the route data object
    HashMap<Integer, AMapNaviPath> naviPaths = AMapNavi.getInstance(this).getNaviPaths();
    // Draw and display the path
    // ...
}

You can also start cycling or walking navigation directly:

@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult routeResult) {
    // Start navigation
    AMapNavi.getInstance(this).startNavi(NaviType.GPS);
}

If route planning fails, the onCalculateRouteFailure callback of AMapNaviListener is triggered. You can implement your error handling logic within this callback.

Cycling and Walking Navigation Adaptation

The driving scenario has been upgraded to use a custom view aligned with the component architecture, while the cycling and walking scenarios still use the legacy implementation. Use the following interface to check the legacy compatibility state. Pass false for the driving scenario and true for the cycling/walking scenario.

AMapNavi.getInstance(this.getApplicationContext()).setIsNaviTravelView(true);