我正在尝试通过 CLLocation 的 course 方法获取有关用户(NSWO)所采取方向的信息。我正在使用这段代码:
double course;
bool isNord;
course = currentLocation.course;
NSLog(@"Current course: %f", course);
NSInteger courseString = course;
//_labelCompass.text = [NSString stringWithFormat:@"%d", courseString];
if (courseString == -1) {
_labelCompass.text = @"N/A";
}
if (courseString >= 22 && courseString <= 67) {
isNord = false;
_labelCompass.text = @"NE";
}
if (courseString >=67 && courseString <= 112) {
isNord = false;
_labelCompass.text = @"E";
}
if (courseString >= 112 && courseString <= 157) {
isNord = false;
_labelCompass.text = @"SE";
}
if (courseString >= 157 && courseString <= 208) {
isNord = false;
_labelCompass.text = @"S";
}
if (courseString >= 208 && courseString <= 247) {
isNord = false;
_labelCompass.text = @"SW";
}
if (courseString >= 247 && courseString <= 292) {
isNord = false;
_labelCompass.text = @"W";
}
if (courseString >= 292 && courseString <= 337) {
isNord = false;
_labelCompass.text = @"NW";
}
if (isNord == true) {
_labelCompass.text = @"N";
}
当然我把这个放进去
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
课程信息更新成功。使用这种算法,我无法像其他人一样知道课程何时是北方,所以我建立了这个。还有比这更好的方法吗?非常感谢。