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];
}
_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];
}
相关文章推荐
- 牛逼的ios在github上的库
- iOS—dictionary写入文件出现的几个问题
- iOS 9 新特性之实现 3D Touch 就是 So easy -- OC版
- iOS 国际化多语言设置 xcode7
- 第三方分享遇到的特殊问题
- IOS--引导页面
- iOS开发的未来
- lldb调试到ios的main函数
- CGContextSaveGState与CGContextRestoreGState的作用 (转)
- Nagios监控Windows服务器
- iOS图片的异步加载
- library not found for IPods/xxxx库 解决办法
- iOS单例解析
- iOS开发者账号添加子账号
- iOS瀑布流
- 简单彩虹动画的效果实现
- iOS 调用系统发短信功能
- Xamarin iOS 让图片动起来,做一个简单的俄罗斯轮盘
- iOS9问题汇总
- iOS bundle id的作用