导航
来源:互联网 发布:spss统计软件百科 编辑:程序博客网 时间:2024/04/28 20:35
@property (nonatomic, strong) CLLocationManager *mgr;
// 上一次的位置
@property (nonatomic, strong) CLLocation *previousLocation;
// 总路程
@property (nonatomic, assign) CLLocationDistance sumDistance;
// 总时间
@property (nonatomic, assign) NSTimeInterval sumTime
- (void)viewDidLoad {
[super viewDidLoad];
// 1.创建定位管理者
// CLLocationManager *mgr = [[CLLocationManager alloc] init];
// 2.设置代理
self.mgr.delegate = self;
// 3.判断是否是iOS8
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) {
// 主动请求授权
[self.mgr requestAlwaysAuthorization];
}
// 3.开始定位
[self.mgr startUpdatingLocation];
}
// CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager )manager didUpdateLocations:(NSArray )locations{
// CLLocation; timestamp 当前获取到为止信息的时间
/*
获取走了多远(这一次的位置 减去上一次的位置)
获取走这段路花了多少时间 (这一次的时间 减去上一次的时间)
获取速度 (走了多远 / 花了多少时间)
获取总共走的路程 (把每次获取到走了多远累加起来)
获取平均速度 (用总路程 / 总时间)
*/
// 获取当前的位置
CLLocation *newLocation = [locations lastObject];
if (self.previousLocation != nil) {
// 计算两次的距离(单位时米)
CLLocationDistance distance = [newLocation distanceFromLocation:self.previousLocation];
// 计算两次之间的时间(单位只秒)
NSTimeInterval dTime = [newLocation.timestamp timeIntervalSinceDate:self.previousLocation.timestamp];
// 计算速度(米/秒)
CGFloat speed = distance / dTime;
// 累加时间
self.sumTime += dTime;
// 累加距离
self.sumDistance += distance;
// 计算平均速度
CGFloat avgSpeed = self.sumDistance / self.sumTime;
NSLog(@”距离%f 时间%f 速度%f 平均速度%f 总路程 %f 总时间 %f”, distance, dTime, speed, avgSpeed, self.sumDistance, self.sumTime);
}
// 纪录上一次的位置
self.previousLocation = newLocation;
}
// 懒加载
- (CLLocationManager *)mgr{
if (!_mgr) {
self.mgr = [[CLLocationManager alloc] init];
}
return _mgr;
}
//在做导航的时候,只需要添加你的控件,把相应的值取上就是。
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 导航
- 横向导航/顶部导航
- 垂直导航/侧面导航
- 页码导航
- 导航菜单
- 积累的力量(《把时间当作朋友》读书笔记)
- 【[INFO] The plugin 'org.apache.maven.plugins:maven-archetype-plugin' does not exist】解决方案
- Linux环境下静态库的生成和使用 (.a文件)
- jquery使用jsonp进行跨域调用
- MySQL的编码字符集问题
- 导航
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core
- 日期、时间选择对话框
- jquery对象和dom对象的区别
- C++ 中list的使用说明
- H.264 基础及 RTP 封包详解
- android的默认参数的修改
- 反正我觉得没救了,已血崩
- 2015个人年终总结