/**
* CLLocation 详解
* coordinate : 经纬度—–位置 结构体( latitude纬度 ,long精度)
* altitude : 海拔—–高度(模拟器是没有的)
* course : 航向 —–(正北0 –360)
* speed ; 速度
*/

CLLocation *location = [locations lastObject];

NSString *directionString = nil;

//方向

int direction  = (int)location.course /90;

switch (direction) {
    case 0:
        directionString = @"北偏东";
        break;
    case 1:
        directionString =@"东偏南";
        break;
    case 2:
        directionString =@"南偏西";
        break;
    case 3:
        directionString =@"西偏北";
        break;
    default:
        break;
}

//角度
int angle = (int)location.course %90;

//速度

//距离
double distance;

if (_oldLocation != 0) {

    //Location可以用一个方法算距离

    distance =  [location distanceFromLocation:_oldLocation];

}
_oldLocation = location;

//拼接字符串
NSString* string = [NSString stringWithFormat:@"%@%d度方向,移动了%.2f,速度为%.2f",directionString,angle,distance,location.speed];

NSLog(@"%@",string);
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐