高德地图 正向地理编码 逆向地理编码

本文介绍如何使用高德地图SDK实现正向和逆向地理编码,包括根据地名定位当前位置及根据经纬度获取地名的具体实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


设置检索KEY的方法 : [AMapSearchServices sharedServices].apiKeyapiKey;

-------------------------------------------------------------------------------------------------------

#pragma mark -- 正向地理编码 (根据地名定位当前位置)

Address 用户当前位置:

- (void)getDefaultUserLocationWithAddress:(NSString *)address {

    self.searchAPI = [[AMapSearchAPI alloc] init];  

    self.searchAPI.delegate = self;

    //构造AMapGeocodeSearchRequest对象,address为必选项,city为可选项

    AMapGeocodeSearchRequest *searchRequest = [[AMapGeocodeSearchRequest alloc] init];

    searchRequest.address = address;

    //发起正向地理编码

    [self.searchAPI AMapGeocodeSearch: searchRequest];

}

- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response

{

    if (response.geocodes.count == 0) {

        return;

    }

    NSArray *locationInfo = response.geocodes; // 用户位置信息

    AMapGeocode *geocode = locationInfo.firstObject;

    AMapGeoPoint *geoPoint = geocode.location;

    CLLocationCoordinate2D Coordinate2D = CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude); // 根据地址获取的经纬度

    [self.mapView setCenterCoordinate:Coordinate2D animated:YES];// 在地图上设置出该位置

    NSString *geocodeString = [NSString stringWithFormat:@"经纬度:%f,%f", geoPoint.latitude, geoPoint.longitude];

}*/


#pragma mark -- 逆向地理编码 (根据经纬度获取地名)

// latitude longtitud 传入经纬度

- (void)getNameByLatitude:(CLLocationDegrees)latitude andLongTitude:(CLLocationDegrees)longtitud 

{

    self.searchAPI = [[AMapSearchAPIalloc]init];

    self.searchAPI.delegate =self;

    AMapReGeocodeSearchRequest *regeoRequest = [[AMapReGeocodeSearchRequestalloc]init];

    regeoRequest.location = [AMapGeoPointlocationWithLatitude:latitudelongitude:longtitud];

    regeoRequest.radius =2000;

    regeoRequest.requireExtension =YES;

    [self.searchAPIAMapReGoecodeSearch: regeoRequest];  // 发起检索

}


- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response

{

    if (![DDUtilsisNullOrNil:response.regeocode]) {

        AMapReGeocode *regeocode = response.regeocode;

        CLLocationDegrees latitude = request.location.latitude;

        CLLocationDegrees longitude = request.location.longitude;

        NSString *address = regeocode.formattedAddress; // 获得检索位置 

    } 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值