[汇文教育]定位系统的实现
2015-03-30 22:16
176 查看
xcode模拟器中不能实现自动定位,需要到真机上运行。
IOS8获取当前经纬度、地理位置
/*集成说明:
1、在plist添加
NSLocationAlwaysUsageDescription = 将根据您的地理位置信息,提供精准服务
NSLocationWhenInUseUsageDescription = 若不允许,您将无法使用地图定位等相关的功能
2、导入CCLocationManager.h头文件,使用CLLocationManager
代理方法;
3、通过block回调获取经纬度、地理位置等
*/
IOS8获取当前经纬度、地理位置
/*集成说明:
1、在plist添加
NSLocationAlwaysUsageDescription = 将根据您的地理位置信息,提供精准服务
NSLocationWhenInUseUsageDescription = 若不允许,您将无法使用地图定位等相关的功能
2、导入CCLocationManager.h头文件,使用CLLocationManager
代理方法;
- (void) getLocationCoordinate:(LocationBlock) locaiontBlock withAddress:(NSStringBlock) addressBlock { self.locationBlock = [locaiontBlock copy]; self.addressBlock = [addressBlock copy]; [self startLocation]; }
- (void) getLocationCoordinate:(LocationBlock) locaiontBlock { self.locationBlock = [locaiontBlock copy]; [self startLocation]; }
<strong>CLLocationManager 代理方法</strong>
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSUserDefaults *standard = [NSUserDefaults standardUserDefaults]; CLGeocoder *geocoder=[[CLGeocoder alloc]init]; [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks,NSError *error) { if (placemarks.count > 0) { CLPlacemark *placemark = [placemarks objectAtIndex:0]; _lastCity = [NSString stringWithFormat:@"%@%@",placemark.administrativeArea,placemark.locality]; [standard setObject:_lastCity forKey:CCLastCity];//省市地址 NSLog(@"______%@",_lastCity); _lastAddress = [NSString stringWithFormat:@"%@%@%@%@%@%@",placemark.country,placemark.administrativeArea,placemark.locality,placemark.subLocality,placemark.thoroughfare,placemark.subThoroughfare];//详细地址 NSLog(@"______%@",_lastAddress); } if (_cityBlock) { _cityBlock(_lastCity); _cityBlock = nil; } if (_addressBlock) { _addressBlock(_lastAddress); _addressBlock = nil; } }]; _lastCoordinate = CLLocationCoordinate2DMake(newLocation.coordinate.latitude ,newLocation.coordinate.longitude ); if (_locationBlock) { _locationBlock(_lastCoordinate); _locationBlock = nil; } NSLog(@"%f--%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude); [standard setObject:@(newLocation.coordinate.latitude) forKey:CCLastLatitude]; [standard setObject:@(newLocation.coordinate.longitude) forKey:CCLastLongitude]; [manager stopUpdatingLocation]; } <strong>系统定位</strong> -(void)startLocation { if([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) { _manager=[[CLLocationManager alloc]init]; _manager.delegate=self; _manager.desiredAccuracy = kCLLocationAccuracyBest; [_manager requestAlwaysAuthorization]; _manager.distanceFilter=100; [_manager startUpdatingLocation]; } else { UIAlertView *alvertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"需要开启定位服务,请到设置->隐私,打开定位服务" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alvertView show]; } }
3、通过block回调获取经纬度、地理位置等
*/
-(void)getLat { __block __weak ViewController *wself = self; if (IS_IOS8) { [[CCLocationManager shareLocation] getLocationCoordinate:^(CLLocationCoordinate2D locationCorrrdinate) { NSLog(@"%f %f",locationCorrrdinate.latitude,locationCorrrdinate.longitude); [wself setLabelText:[NSString stringWithFormat:@"%f %f",locationCorrrdinate.latitude,locationCorrrdinate.longitude]]; }]; } } -(void)getCity { __block __weak ViewController *wself = self; if (IS_IOS8) { [[CCLocationManager shareLocation]getCity:^(NSString *cityString) { NSLog(@"%@",cityString); [wself setLabelText:cityString]; }]; } }
相关文章推荐
- 手机内置的定位系统是怎么实现定位的
- 嵌入式系统上实现GPS全球定位功能
- Android 系统api实现定位及使用百度提供的api来实现定位
- 模仿系统PE重定位实现
- 基于高德地图实现移动互联网地图定位自动检索系统
- 运用百度地图API离线版(在线版)实现网管系统中终端定位和终端信息获取的功能
- iOS 系统地图实现及定位
- 在Android系统上定位功能实现方法
- IOS CoreLocation实现系统自带定位的方法
- 在Android系统上定位功能实现方法
- 老男孩教育每日一题-2017年5月12日-磁盘知识点:linux系统中LVM配置实现方法?
- 利用云视频实现在线教育和美女主播系统。
- 北斗GPS两系统实现兼容互操作 提升导航定位精度
- [汇文教育]关于XMPP协议来来实现IOS中即时通讯的浅谈
- 传智播客-- 教育办公系统集成 spring-security 框架实现权限模块
- 在3G中实现LBS的定位技术和GIS系统
- 实现-汽车牌照识别系统中车牌定位与校正及字符分割的研究
- 传智播客-- 教育办公系统角色模块的增删改查实现
- Windows系统通过注册表实现打开CMD并定位到指定文件夹
- 传智播客--教育办公系统的OpenSessionInView,通用翻页的实现