Cycling Routing
This guide describes how to use the map SDK's search functionality to plan a cycling route. The planned routes are suitable for bicycle travel.
Note: This feature requires the search library (AMapSearchKit.framework). Make sure it is imported into your project.
Cycling route planning is supported from search library version 4.3.0 onwards.
Before You Begin
Before you start, ensure you have completed the following steps:
1. Import the required header files.
2. Configure your API key.
3. Define and initialize the AMapSearchAPI object.
Step 1: Import Header Files
Import the AMapFoundationKit.h and AMapSearchKit.h header files.
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapSearchKit/AMapSearchKit.h>Step 2: Configure Your API Key
You must add your API key to use the search functionality.
For search library v4.x:
You need to import the base SDK (AMapFoundationKit.framework). Set the key as follows:
[AMapServices sharedServices].apiKey = @"Your API Key";For search library v3.x or earlier:
It is recommended to update to the latest version. If you are using v3.x, set the key as follows:
[AMapSearchServices sharedServices].apiKey = @"Your API Key";Step 3: Define the AMapSearchAPI Object
Declare a property for the main search object, AMapSearchAPI, and conform to the AMapSearchDelegate protocol.
Step 4: Initialize the AMapSearchAPI Object
Initialize the search object and set its delegate.
self.search = [[AMapSearchAPI alloc] init];
self.search.delegate = self;Plan a Cycling Route
Follow these steps to plan a cycling route.
Step 5: Set Route Planning Parameters
The request class for cycling route planning is AMapRidingRouteSearchRequest. The origin (start coordinate) and destination (end coordinate) parameters are required.
self.startAnnotation.coordinate = self.startCoordinate;
self.destinationAnnotation.coordinate = self.destinationCoordinate;
AMapRidingRouteSearchRequest *navi = [[AMapRidingRouteSearchRequest alloc] init];
/* Start point. */
navi.origin = [AMapGeoPoint locationWithLatitude:self.startCoordinate.latitude
longitude:self.startCoordinate.longitude];
/* Destination. */
navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationCoordinate.latitude
longitude:self.destinationCoordinate.longitude];Step 6: Initiate the Route Search
Call the AMapRideRouteSearch method on the AMapSearchAPI object to start the route planning request.
[self.search AMapRidingRouteSearch:navi]; Step 7: Handle the Response
When the search is successful, the onRouteSearchDone callback is triggered. In this callback, parse the AMapRouteSearchResponse object to display the planned route on the map.
Notes:
1. Parse the response object in the callback to retrieve the cycling path.
2. The response.route.paths property provides a list of AMapPath objects. Refer to the AMapPath class for detailed information about the cycling plan.
3. The structure of the route planning result is shown in the diagram below. Use this structure to parse the result and display the route accurately.

- (void)onRouteSearchDone:(AMapRouteSearchBaseRequest *)request response:(AMapRouteSearchResponse *)response {
if (response.route == nil) {
return;
}
// Parse the response to extract path information; see the Demo for details.
}Handle Errors
If the search fails, the didFailWithError callback is triggered. Use this callback to identify the reason for the failure.
- (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error {
NSLog(@"Error: %@", error);
}