Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Determining the Heading in Landscape Mod... > Determining the Heading in Landscape... - Pg. 89

Feedback: 0 Comments on this Section

float trueHeading = [self trueHeading:newHeading.trueHeading fromOrientation:device.orientation]; magneticHeadingLabel.text = [NSString stringWithFormat:@"%f", magneticHeading]; trueHeadingLabel.text = [NSString stringWithFormat:@"%f", trueHeading]; float heading = -1.0f * M_PI * newHeading.magneticHeading / 180.0f;!!CO1!! arrowImage.transform = CGAffineTransformMakeRotation(heading); } } 1. You should use the directly reported newHeading.magneticHeading for the compass needle rather than the adjusted heading otherwise the compass will not point correctly. Make sure you've saved all the changes to the implementation file and click on the Build and Run button in the Xcode toolbar to deploy the application onto the device. If all goes well you should see the same compass display as before. However this time if you rotate the display, sees Figure 6-7, the heading values should be the same irrespective of the device orientation. Figure 6-7. Heading values are now the same irrespective of orientation Although we have not discussed it here, remember that if the CLLocationManager object encounters an error, it will call the locationManager:didFailWithError: delegate method. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { if ([error code] == kCLErrorDenied) { // User has denied the application's request to use location services. [manager stopUpdatingHeading]; } else if ([error code] == kCLErrorHeadingFailure) { // Heading could not be determined } } For more information about this delegate method and the error codes that it handles refer back to Chapter 3.