Document Maps SDK for iOS Guides Utility Library Distance Matrix

Distance Matrix

The distance measurement feature is available from Search SDK version 6.1.0. It enables distance calculation without requesting the driving route planning API. Currently, both straight-line distance and driving distance are supported.

Step 1: Initialize the Request

Initialize an AMapDistanceSearchRequest object.

AMapDistanceSearchRequest *request = [[AMapDistanceSearchRequest alloc] init];

Step 2: Implement the Delegate Callback

Implement the onDistanceSearchDone:response: delegate method to handle the search results.

- (void)onDistanceSearchDone:(AMapDistanceSearchRequest *)request response:(AMapDistanceSearchResponse *)response {
    // Handle the response
}

Step 3: Set Search Parameters

Configure the origin coordinates, destination coordinates, and distance type.

AMapDistanceSearchRequest *request = [[AMapDistanceSearchRequest alloc] init];
request.origins = @[
    [AMapGeoPoint locationWithLatitude:39.989643 longitude:115.481028]
];
request.destination = [AMapGeoPoint locationWithLatitude:40.004717 longitude:114.465302];
request.type = 1;

Step 4: Send the Request

Use the AMapDistanceSearch: method of AMapSearchAPI to send the request.

[self.search AMapDistanceSearch:request];

Step 5: Receive and Parse the Response

Process the returned data in the onDistanceSearchDone:response: callback. For details on the response structure, refer to the AMapDistanceSearchResponse class.

If an error occurs, the AMapSearchRequest:didFailWithError: delegate method is called.

- (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error {
    // Handle the error
}