iOS 百度地图反编码地理位置信息

1:创建

_locService = [[BMKLocationService alloc]init];

    _geocodesearch = [[BMKGeoCodeSearch alloc]init];
    _geocodesearch.delegate = self;

    _locService.delegate = self;

2:开始定位

_locService.desiredAccuracy = kCLLocationAccuracyBest;//设置定位精度
 [_locService startUserLocationService];

3:实现delegate

#pragma mark -定位成功
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{
    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    NSString *lat = [NSString stringWithFormat:@"%f",userLocation.location.coordinate.latitude];
    NSString *lon = [NSString stringWithFormat:@"%f",userLocation.location.coordinate.longitude];
    UZGPersonalSetting *s=[UZGPersonalSetting getInstance];
    s.currLocationl=[NSString stringWithFormat:@"%f,%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude];
    CLLocationCoordinate2D pt = (CLLocationCoordinate2D){0, 0};
    if (lat!=nil && lon!=nil) {
        pt = (CLLocationCoordinate2D){[lat floatValue], [lon floatValue]};
    }
    BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
    reverseGeocodeSearchOption.reverseGeoPoint = pt;
    BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
    if(flag) NSLog(@"反geo检索发送成功");
}

#pragma mark -定位失败
- (void)didFailToLocateUserWithError:(NSError *)error{
    if (error.code == 1) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"定位服务未开启" message:@"请进入系统设置内开启定位服务(设置-->隐私-->定位服务-->XXX)" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:@"设置", nil];
        [[alert rac_buttonClickedSignal] subscribeNext:^(NSNumber *indexNumber) {
            if ([indexNumber intValue] == 1) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
            }
        }];
        [alert show];
    }else{
        [MBProgressHUD showError:@"定位失败,请稍后再试"];
    }
}

4:实现反编码的delegate

-(void) onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error {
    UZGPersonalSetting *s = [UZGPersonalSetting getInstance];
    s.locateAddress = result.address;
    _locateShop = [[ViewControllerHttpLocateShop alloc]init];
    _locateShop.delegate=self;
    [_locateShop initHttpLocateShop];
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值