开发 Maps SDK for iOS Guides Utility Library Distance Matrix

Distance Matrix 最后更新时间: 2026年07月02日

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
}

返回顶部 示例中心 常见问题 智能客服 公众号
二维码