Headless Planning
Overview
Independent route calculation allows you to compute a route without automatically applying the result to the current navigation session. You must manually call the API to start navigation using the calculated route. This feature is ideal for scenarios where you need to preview a route without interrupting ongoing navigation. It supports the following transport modes:
- Driving / Truck route calculation
- Walking route calculation
- Cycling route calculation
The following route calculation methods are supported:
- Route calculation without a start point: Leave the start coordinate empty.
- Route calculation with coordinates: Provide only latitude and longitude for the start and end points in AMapNaviPOIInfo.
- Route calculation with POI IDs: Provide POI IDs for the start and end points to improve accuracy.
Independent Route Calculation
To implement independent route calculation, use the following APIs.
Driving / Truck Route Calculation
/**
* @brief Calculates a route independently without affecting the current navigation session. Available since 7.7.0.
* @param startPOIInfo The start POI info. See AMapNaviPOIInfo. Pass nil to use "My Location" as the start point.
* If startPOIInfo is not nil and the POI ID is valid, the ID is used for route calculation;
* otherwise, the coordinate point is used.
* @param endPOIInfo The end POI info. See AMapNaviPOIInfo. If the POI ID is valid, the ID is used for route
* calculation; otherwise, the coordinate point is used. Note: The POI ID and coordinate point
* cannot both be empty.
* @param wayPOIInfos An array of waypoint POI infos. Supports up to 16 waypoints; any additional waypoints are
* ignored. If the POI ID is valid, the ID is used for route calculation; otherwise, the
* coordinate point is used. Note: The POI ID and coordinate point cannot both be empty.
* @param strategy The route calculation strategy. We recommend using AMapNaviDrivingStrategyMultipleDefault,
* which matches the default strategy of the AMap app (avoid congestion, prefer speed, avoid tolls).
* @param callback The callback upon route calculation completion. On success, routeGroup is not nil.
* On failure, error is not nil. See AMapNaviCalcRouteState for error codes.
* @return Whether the parameters are valid. This does not indicate whether the route calculation succeeded.
*/
- (BOOL)independentCalculateDriveRouteWithStartPOIInfo:(nullable AMapNaviPOIInfo *)startPOIInfo
endPOIInfo:(nonnull AMapNaviPOIInfo *)endPOIInfo
wayPOIInfos:(nullable NSArray<AMapNaviPOIInfo *> *)wayPOIInfos
drivingStrategy:(AMapNaviDrivingStrategy)strategy
callback:(nullable void (^)(AMapNaviRouteGroup *_Nullable routeGroup, NSError *_Nullable error))callback;Example
AMapNaviPoint *startPoint = [AMapNaviPoint locationWithLatitude:39.993306 longitude:116.473004];
AMapNaviPoint *endPoint = [AMapNaviPoint locationWithLatitude:39.976941 longitude:116.463375];
AMapNaviPOIInfo *startPOI = [[AMapNaviPOIInfo alloc] init];
startPOI.mid = @""; // POI ID
startPOI.locPoint = startPoint; // Coordinate point
startPOI.startAngle = 0; // Heading angle. Default is -1. 0 = north, increases clockwise.
// Note: Only takes effect when mid == nil, locPoint != nil, and startAngle >= 0.
AMapNaviPOIInfo *endPOI = [[AMapNaviPOIInfo alloc] init];
endPOI.mid = @"B000A81FY5"; // POI ID
endPOI.locPoint = endPoint; // Coordinate point
endPOI.startAngle = 0; // Heading angle (same rules as above).
// Route calculation types:
// 1. Empty start coordinate → route calculation without a start point
// 2. Only coordinates for start and end → route calculation with coordinates
// 3. Only POI IDs for start and end → route calculation with POI IDs
// 4. startAngle, locPoint, and mid all provided → route calculation with start heading
[[AMapNaviDriveManager sharedInstance] independentCalculateDriveRouteWithStartPOIInfo:nil
endPOIInfo:endPOI
wayPOIInfos:nil
drivingStrategy:AMapNaviDrivingStrategyMultipleAvoidCost
callback:^(AMapNaviRouteGroup * _Nonnull routeGroup, NSError * _Nonnull error) {
NSLog(@"group = %@, error = %@", routeGroup, error);
}];Walking Route Calculation
/**
* @brief Calculates a walking route independently. Available since 7.8.0.
* @param startPOIInfo The start POI info. See AMapNaviPOIInfo. Pass nil to use "My Location" as the start point.
* If startPOIInfo is not nil and the POI ID is valid, the ID is used; otherwise, the coordinate
* point is used.
* @param endPOIInfo The end POI info. See AMapNaviPOIInfo. If the POI ID is valid, the ID is used; otherwise,
* the coordinate point is used. Note: The POI ID and coordinate point cannot both be empty.
* @param strategy The route calculation strategy. See AMapNaviTravelStrategy.
* @param callback The callback upon route calculation completion. On success, routeGroup is not nil.
* On failure, error is not nil. See AMapNaviCalcRouteState for error codes.
* @return Whether the parameters are valid. This does not indicate whether the route calculation succeeded.
*/
- (BOOL)independentCalculateWalkRouteWithStartPOIInfo:(nullable AMapNaviPOIInfo *)startPOIInfo
endPOIInfo:(nonnull AMapNaviPOIInfo *)endPOIInfo
strategy:(AMapNaviTravelStrategy)strategy
callback:(nullable void (^)(AMapNaviRouteGroup *_Nullable routeGroup, NSError *_Nullable error))callback;Cycling Route Calculation
/**
* @brief Calculates a cycling route independently. Available since 7.7.0.
* @param startPOIInfo The start POI info. See AMapNaviPOIInfo. Pass nil to use "My Location" as the start point.
* If startPOIInfo is not nil and the POI ID is valid, the ID is used; otherwise, the coordinate
* point is used.
* @param endPOIInfo The end POI info. See AMapNaviPOIInfo. If the POI ID is valid, the ID is used; otherwise,
* the coordinate point is used. Note: The POI ID and coordinate point cannot both be empty.
* @param strategy The route calculation strategy. See AMapNaviTravelStrategy.
* @param callback The callback upon route completion. On success, routeGroup is not nil.
* On failure, error is not nil. See AMapNaviCalcRouteState for error codes.
* @return Whether the parameters are valid. This does not indicate whether the route calculation succeeded.
*/
- (BOOL)independentCalculateRideRouteWithStartPOIInfo:(nullable AMapNaviPOIInfo *)startPOIInfo
endPOIInfo:(nonnull AMapNaviPOIInfo *)endPOIInfo
strategy:(AMapNaviTravelStrategy)strategy
callback:(nullable void (^)(AMapNaviRouteGroup *_Nullable routeGroup, NSError *_Nullable error))callback;Navigation
The route result from independent route calculation can be used for route preview or to start navigation directly. When used for navigation, you can also select a specific route before starting.
// Start GPS navigation
[[AMapNaviDriveManager sharedInstance] startGPSNavi:independentRouteGroup];
// Start simulated navigation
[[AMapNaviDriveManager sharedInstance] startEmulatorNavi:independentRouteGroup];Example: Start Navigation Using an Independently Calculated Driving Route
[[AMapNaviDriveManager sharedInstance] independentCalculateDriveRouteWithStartPOIInfo:nil endPOIInfo:endPOI wayPOIInfos:nil drivingStrategy:AMapNaviDrivingStrategyMultipleAvoidCost callback:^(AMapNaviRouteGroup * _Nonnull routeGroup, NSError * _Nonnull error) {
// 1. Get the result of the independent route calculation
AMapNaviRouteGroup *independentRouteGroup = routeGroup;
NSNumber *lastRouteIDs = [independentRouteGroup.naviRouteIDs lastObject];
// 2. Pre-trip route selection
[independentRouteGroup selectNaviRouteWithRouteID:[lastRouteIDs integerValue]];
// 3. Start navigation using the independently calculated route
[[AMapNaviDriveManager sharedInstance] startGPSNavi:independentRouteGroup];
}];