[英]iPhone - How do i get direction with degree based location
这实际上非常简单。 纬度从赤道的0°开始,北极为90.0,南极为-90.0。 基本上,如果纬度在0到90之间,那么您在北半球和南半球的纬度在0到-90之间。
经度基本上以相同的方式工作。 0°表示本初子午线,它是一条穿过格林威治,英格兰和非洲部分地区的假想线。 最高经度为180°的正经度是指本初子午线以东的位置,而负经度是指本初子午线以西180度以内的区域。
使用此代码并将CLLocationManagerDelegate放在.h文件中
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
updatedHeading = newHeading.magneticHeading;
float headingFloat = 0 - newHeading.magneticHeading;
rotateImg.transform = CGAffineTransformMakeRotation(headingFloat*radianConst);
float value = updatedHeading;
if(value >= 0 && value < 23)
{
compassFault.text = [NSString stringWithFormat:@"%f° N",value];
}
else if(value >=23 && value < 68)
{
compassFault.text = [NSString stringWithFormat:@"%f° NE",value];
}
else if(value >=68 && value < 113)
{
compassFault.text = [NSString stringWithFormat:@"%f° E",value];
}
else if(value >=113 && value < 185)
{
compassFault.text = [NSString stringWithFormat:@"%f° SE",value];
}
else if(value >=185 && value < 203)
{
compassFault.text = [NSString stringWithFormat:@"%f° S",value];
}
else if(value >=203 && value < 249)
{
compassFault.text = [NSString stringWithFormat:@"%f° SE",value];
}
else if(value >=249 && value < 293)
{
compassFault.text = [NSString stringWithFormat:@"%f° W",value];
}
else if(value >=293 && value < 350)
{
compassFault.text = [NSString stringWithFormat:@"%f° NW",value];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.