您的位置:首页 > 移动开发 > IOS开发

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

2015-10-27 17:09 155 查看
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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: