iOS Mapkit 定位REGcode地理位置偏移

在iOS上,使用系统Mapkit定位,获取到的坐标会有偏移;

今有需求,用系统Mapkit定位,并Regcode出实际地理位置,修正偏移;

解决方案:

   使用MapView的代理

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation NS_AVAILABLE(10_9, 4_0);

获取坐标,然后根据这个坐标解码出实际地址就行了!

大致流程:

  1. 导入MapKit框架,并在使用时,引入:mapkit
  2. 初始化一个mapView ,并showUserLocation 

    self.theMapView = [[MKMapViewalloc]initWithFrame:CGRectZero];

    _theMapView.showsUserLocation = YES;

    _theMapView.delegate = self;

  3:在代理方法中处理就可以了

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation NS_AVAILABLE(10_9, 4_0);

{

    //这里得到的userLocation,已经是偏移后的位置了

       CLGeocoder *gcode = [[CLGeocoderalloc]init];

    NSLog(@"line<%d> %s",__LINE__,__func__);

    [gcode reverseGeocodeLocation:userLocation.locationcompletionHandler:^(NSArray *placemarks, NSError *error) {

        if([placemarks count] >0)

        {

            MKPlacemark *pleaceMark = [placemarks objectAtIndex:0];

            self.theAddress = [[pleaceMark.addressDictionary objectForKey:@"FormattedAddressLines"] JSONString];

            NSLog(@"%@",_theAddress);

            mapView.showsUserLocation = NO;

        }

    }];

    

 }

 

参考:http://blog.csdn.net/duanhai189/article/details/8373950

转载于:https://www.cnblogs.com/cocoajin/p/3467231.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值