我们在使用百度地图定位成功后,一般会使用反地理编码的方式进行地址解析,获取地址信息供我们应用使用,如下方法所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | // 获取地址位置后调用方法 - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation { /* ????code for location... ?*/ ????????// 反地址编码获取地址 ????????BMKReverseGeoCodeOption *option = [[BMKReverseGeoCodeOption alloc] init]; ????????option.reverseGeoPoint = userLocation.location.coordinate; ????????? ????????SALog(@"开始反地理编码..."); ????????? ????????if (![self.geoCode reverseGeoCode:option]){ ????????????SALog(@"反地址编码失败,使用Apple地图反地理编码"); ????????????CLLocationCoordinate2D newCoor = [[self class] GCJ02FromBD09:userLocation.location.coordinate]; ????????????CLLocation *location = [[CLLocation alloc] initWithLatitude:newCoor.latitude longitude:newCoor.longitude]; ????????????[[[CLGeocoder alloc] init] reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) { ????????????????CLPlacemark *placemark = [placemarks firstObject]; ????????????????SALog(@"%@ - %@", placemark.name, placemark.locality); /* ????code for address... ?*/ ????????????}]; ????????} ????????// 结束 ????} } |
[……]