CLLocationManager and title degrees in iPhone

Using the CLLocationManager didUpdateHeading object, how can I convert the resulting .x and heading.y header values ​​to degrees that I can overlay on the compass image?

+3
source share
3 answers

For degree headings, you can use magneticHeadingand trueHeadinginstead of xand y.

trueHeading

The title (measured in degrees) relative to the true North. (Only for reading)

@property(readonly, nonatomic) CLLocationDirection trueHeading

Discussion

, . , . 0 , 90 - , 180 .. , .

+3

Try:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {

   CLLocationDirection trueNorth = [newHeading trueHeading];

   CLLocationDirection magneticNorth = [newHeading magneticHeading];

}

CLLocationDirection typedef double .

+1

uiimageview . .

if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
            NSLog(@"UIInterfaceOrientationLandscapeLeft");
            [self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading - 90) *3.14/180)*-1) )];

        }else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
            NSLog(@"UIInterfaceOrientationLandscapeRight");
            [self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading + 90) *3.14/180)*-1))];

        }else if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
            NSLog(@"UIInterfaceOrientationPortraitUpsideDown");
            [self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading + 180) *3.14/180)*-1) )];

        }else{
            NSLog(@"Portrait");
            [self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((newHeading.magneticHeading *3.14/180)*-1)];
        }
+1

Source: https://habr.com/ru/post/1728070/


All Articles