1.根据CLGeocoder reverseGeocodeLocation方法获取地址信息
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation: userLocation.location completionHandler:^(NSArray*array, NSError *error) {
if (array.count > 0) {
CLPlacemark *placemark = [array objectAtIndex:0];
if (placemark != nil) {
NSArray *lines = placemark.addressDictionary[@"FormattedAddressLines"];
NSString *addressString = [lines componentsJoinedByString:@"\n"];
NSLog(@"Address: %@", addressString);
}
}
}];
2.根据BMKGeoCodeSearchDelegate来获取地址信息
BMKReverseGeoCodeOption *reverseGeoCodeOption = [[BMKReverseGeoCodeOptionalloc] init];
reverseGeoCodeOption.reverseGeoPoint = coord;
BOOL result = [_bmkGeoCodeSearchreverseGeoCode:reverseGeoCodeOption];
if (!result) {
[selfreturnError:@"获取地理位置失败"callback:_getAddressLocationCallback];
}
#pragma mark - BMKGeoCodeSearchDelegate
- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
if (error ==BMK_SEARCH_NO_ERROR) {
NSDictionary *resultDic =@{
@"address":result.address
};
[selfreturnSuccess:resultDic cancelled:NOcallback:_getAddressLocationCallback];
}
else{
[selfreturnError:@"逆地址编码失败"callback:_getAddressLocationCallback];
}
}