示例中心
功能在线体验
控制台

高德 开发 iOS 地图SDK 开发指南 地图计算工具 距离测量

更新时间:2018年04月20日

从搜索功能6.1.0 版本开始支持距离测量功能。使用此方法可以在不请求驾车出行路线规划接口的同时完成距离计算。目前支持直线距离和驾车距离的测量。

第 1 步,初始化 AMapDistanceSearchRequest 

AMapDistanceSearchRequest *request = [[AMapDistanceSearchRequest alloc] init];
let request = AMapDistanceSearchRequest()

第 2 步, 实现代理回调 

- (void)onDistanceSearchDone:(AMapDistanceSearchRequest *)request response:(AMapDistanceSearchResponse *)response
{
}
func onDistanceSearchDone(_ request: AMapDistanceSearchRequest!, response: AMapDistanceSearchResponse!) {
    }

第 3 步,设置搜索参数

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;
let request = AMapDistanceSearchRequest()
        request.origins = [AMapGeoPoint.location(withLatitude: 39.989643, longitude: 115.481028)
        request.destination = AMapGeoPoint.location(withLatitude: 40.004717, longitude: 114.465302)

第 4 步,发送请求

使用AMapSearchAPI的AMapDistanceSearch接口

[self.search AMapDistanceSearch:request];
search .aMapDistanceSearch(request)

第 5 步, 接收并解析数据  

在onDistanceSearchDone回调中处理返回的数据,具体返回信息见AMapDistanceSearchResponse 类。

如果发生错误,会回调AMapSearchRequest:(id)request didFailWithError:(NSError *)error方法。

移动端
示例中心
功能
在线体验
常见问题