Document Navigation SDK for Android Guides Route Planning Electric Bike Routing

Electric Bike Routing

Overview

The AMapNavi interface provides multiple route planning methods for this purpose.

Important: Electric bike route planning is a paid feature. Whether you are applying for a trial or a production deployment, please submit a business cooperation ticket through the ticket system. Otherwise, route calculation will fail by default.

Notes

- Route planning requires an internet connection.

- Origin and destination information can be obtained in several ways, such as using the coordinate picker to query coordinates, or using the POI search feature from the Search SDK to find points of interest.

- Three electric bike route planning methods are available, as shown in the table below:

Method

Parameter Description

Return Value

Effect

calculateEleBikeRoute(NaviLatLng to)

to: Destination coordinates

BOOL — indicates whether parameter validation succeeded, not whether route calculation succeeded

Route planning without a specified origin (uses the current location as the origin)

calculateEleBikeRoute(NaviLatLng from, NaviLatLng to)

from: Origin coordinates

to: Destination coordinates

BOOL — indicates whether parameter validation succeeded, not whether route calculation succeeded

Route planning with origin and destination specified by coordinates

calculateEleBikeRoute(NaviPoi fromPoi, NaviPoi toPoi, TravelStrategy strategy)

fromPoi: Origin POI

toPoi: Destination POI

strategy: Route calculation strategy

BOOL — indicates whether parameter validation succeeded, not whether route calculation succeeded

Route planning with origin and destination specified by POI (origin can be null; uses current location as the origin)

It is recommended to use the calculateEleBikeRoute(NaviPoi fromPoi, NaviPoi toPoi, TravelStrategy strategy) method. The SDK automatically completes additional information based on the POI ID, resulting in more reasonable routes and reducing unnecessary detours.

Usage

1. Route Planning by Coordinates

Pass the latitude and longitude of the origin and destination to plan a route.

Electric bike route planning without an origin:

NaviLatLng end = new NaviLatLng(39.917834, 116.397036);
// Route planning by coordinates
AMapNavi.getInstance(this).calculateEleBikeRoute(end);

Electric bike route planning with origin and destination:

// Origin coordinates
NaviLatLng start = new NaviLatLng(39.993308, 116.473199);
// Destination coordinates
NaviLatLng end = new NaviLatLng(39.917834, 116.397036);
// Route planning by coordinates
AMapNavi.getInstance(this).calculateEleBikeRoute(start, end);

2. Route Planning by POI

Pass the POI information of the origin and destination to plan an electric bike route.

2.1 Single Route Planning

// Construct origin POI
NaviPoi start = new NaviPoi("Forbidden City", null, "B000A8UIN8");
// Construct destination POI
NaviPoi end = new NaviPoi("Peking University", null, "B000A816R6");
// Perform electric bike route planning
AMapNavi.getInstance(this).calculateEleBikeRoute(start, end, TravelStrategy.SINGLE);

2.2 Multiple Route Planning

// Construct origin POI
NaviPoi start = new NaviPoi("Forbidden City", null, "B000A8UIN8");
// Construct destination POI
NaviPoi end = new NaviPoi("Peking University", null, "B000A816R6");
// Perform electric bike route planning
AMapNavi.getInstance(this).calculateEleBikeRoute(start, end, TravelStrategy.MULTIPLE);

3. Handling Results

When route planning succeeds, the onCalculateRouteSuccess callback of AMapNaviListener is triggered. In 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 route
    ...
}

You can also start electric bike 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 error handling logic in this callback.