# Magnetometer or Heading / Compass values on iOS 11?

**URL:** <https://forums.unrealengine.com/t/magnetometer-or-heading-compass-values-on-ios-11/405369>\
**Category:** Mobile\
**Tags:** unreal-engine, iOS, iphone, question\
**Created:** [September 24, 2017, 10:02pm UTC](https://forums.unrealengine.com/t/magnetometer-or-heading-compass-values-on-ios-11/405369 "2017-09-24T22:02:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_f8c945b8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f8c945b8](https://forums.unrealengine.com/u/anonymous_user_f8c945b8)\
**Post date:** [September 24, 2017, 10:02pm UTC](https://forums.unrealengine.com/t/magnetometer-or-heading-compass-values-on-ios-11/405369/1 "2017-09-24T22:02:53Z")

</div>

Hi all,

I’m trying to get values or calculate an equalivalent type value to determine which direction (compass degrees) the user is facing and holding their device towards, so I can orient the game world along their relevant axis.

It seems like this would be fairly simple to do based of the readings from the iphone magenetometer or compass heading, but I can’t seem to find any documentation about accessing or calling those features in UE.

Does anyone have any tips for where to begin approaching this? I figure the answer will stretch beyond blueprints, but I’m curious how involved this could become?

Thanks for the help in advance

---

<div class="post-metadata">

**Author:** ![Emixam](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Emixam](https://forums.unrealengine.com/u/Emixam)\
**Post date:** [April 16, 2018, 3:19pm UTC](https://forums.unrealengine.com/t/magnetometer-or-heading-compass-values-on-ios-11/405369/2 "2018-04-16T15:19:52Z")

</div>

Bump, I’m also looking for a way to find the true north

---

<div class="post-metadata">

**Author:** ![Seim2k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Seim2k](https://forums.unrealengine.com/u/Seim2k)\
**Post date:** [March 29, 2019, 11:46am UTC](https://forums.unrealengine.com/t/magnetometer-or-heading-compass-values-on-ios-11/405369/3 "2019-03-29T11:46:58Z")

</div>

Hi,

can someone tell me why are there almost no valuable Information about this topic? It seems like nobody can answer this question. I searched for hours and nowhere I can find some answer leading in a possible direction. But I found some links which are interesting, although I´m sure that anybody who wants to know how we can access the Compass will get to this sooner or later. It´s kind of sobering.

User F3NR1S developed a plugin but iOS is still pending:  
[A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums](https://wiki.unrealengine.com/Magnetic_Field_Toolkit) and  
[https://forums.unrealengine.com/unreal-engine/marketplace/1437192-magnetic-field-toolkit](https://forums.unrealengine.com/unreal-engine/marketplace/1437192-magnetic-field-toolkit)

Apple Dev: [Apple Developer Documentation](https://developer.apple.com/documentation/corelocation/getting_heading_and_course_information) and [Apple Developer Documentation](https://developer.apple.com/documentation/corelocation/clheading)

Medium article about a compass app: [How To Build a Compass App in Swift | by Federico Zanetello | Swiftly Swift | Medium](https://medium.com/swiftly-swift/how-to-build-a-compass-app-in-swift-2b6647ae25e8)  
(But I don´t know how to get access to Swift from Unreal )

How would be the common workflow to execute SwiftCode in Unreal C++?

EDIT: I found a post as a feature request since 4.9 : [[Feature Request] Add magnetometer support for mobile platform - Mobile - Unreal Engine Forums](https://answers.unrealengine.com/questions/302555/feature-request-add-magnetometer-support-for-mobil.html)

---

<div class="post-metadata">

**Author:** ![Seim2k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Seim2k](https://forums.unrealengine.com/u/Seim2k)\
**Post date:** [February 7, 2020, 10:41am UTC](https://forums.unrealengine.com/t/magnetometer-or-heading-compass-values-on-ios-11/405369/4 "2020-02-07T10:41:48Z")

</div>

Although a bit late, but just for Completeness,

I found the solution some time ago by ReImplementing the LocationServices - Plugin written by Epic and extended it with the appropriate Objective-C - Code.

You can take a look at “LocationServicesIOSImpl.cpp” from the Engine-Source for example-code.

I didn´t know how Objective-C works before: here is a good way to start:

[http://cocoadevcentral.com/d/learn\_objectivec/](http://cocoadevcentral.com/d/learn_objectivec/)

and for LocationService in common here:

[https://developer.apple.com/documentation/corelocation/getting\_heading\_and\_course\_information](https://developer.apple.com/documentation/corelocation/getting_heading_and_course_information)

> **[How To Build a Compass App in Swift](https://medium.com/swiftly-swift/how-to-build-a-compass-app-in-swift-2b6647ae25e8)**
>
> ⭐️⭐️⭐️⭐️⭐
> Hi! This post has moved to a new blog! Come over to fivestars.blog for the latest articles!
> ⭐️⭐️⭐️⭐️⭐

[https://developer.apple.com/documentation/corelocation/clheading](https://developer.apple.com/documentation/corelocation/clheading)

> **[Getting the Heading and Course of a Device](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/LocationAwarenessPG/GettingHeadings/GettingHeadings.html#//apple_ref/doc/uid/TP40009497-CH5-SW1)**
>
> Describes the use of location and map services.

> <https://stackoverflow.com/questions/15581230/why-does-my-heading-not-change-using-core-location>

Then we can do something like:

```
    -(void)startUpdatingHeading
    {
        LocManager = [[CLLocationManager alloc] init];
        LocManager.delegate = self;
        
        if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
        {
            //we need to request location services
            //[LocManager requestAlwaysAuthorization];
            [LocManager requestWhenInUseAuthorization];
        }
        if([CLLocationManager headingAvailable])
        {
            
            LocManager.headingFilter = 5;
            // we also need to deliver LocationUpdates, why? i do not know, but it´s recommended in the apple documentation, maybe it´s a parent service ?
            [LocManager startUpdatingLocation];
            [LocManager startUpdatingHeading];
        }
    }
    -(void)stopUpdatingHeading
    {
        if([CLLocationManager headingAvailable])
        {
            [LocManager stopUpdatingLocation];
            [LocManager stopUpdatingHeading];
             
            [LocManager release];
            LocManager = nil;
            
        }
    }
/*
     * Callback from the LocationManager when there is an update to our Heading
     */
    -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
    {
        if(newHeading.headingAccuracy < 0)
        {
            return;
        }
    
        //use Heading if its valid
        CLLocationDirection theHeading = ((newHeading.trueHeading > 0) ?
                                          newHeading.trueHeading : newHeading.magneticHeading);
        FHeadingServicesData headingData;
        headingData.MagneticHeading = (float)theHeading;

// and broadcast this to Unreal

UHeadingServicesBPLibrary::GetHeadingServicesImpl()->OnHeadingChanged.Broadcast(headingData);

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f8c945b8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f8c945b8](https://forums.unrealengine.com/u/anonymous_user_f8c945b8)\
**Post date:** [August 5, 2020, 10:37pm UTC](https://forums.unrealengine.com/t/magnetometer-or-heading-compass-values-on-ios-11/405369/5 "2020-08-05T22:37:15Z")

</div>

I came back to ask this same question from nearly 3 years later and was _so_ thankful to see your reply. The ue4 community is the best!! this solution works 100%, appreciate it!

---

<div class="post-metadata">

**Author:** ![theotherkyle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theotherkyle](https://forums.unrealengine.com/u/theotherkyle)\
**Post date:** [May 25, 2024, 4:26am UTC](https://forums.unrealengine.com/t/magnetometer-or-heading-compass-values-on-ios-11/405369/6 "2024-05-25T04:26:54Z")

</div>

I’m clearly doing something wrong. I’m also attempting to do the above, but seem to be stuck.  
I’ve included location updates in the plist file , made sure to requestwheninuseauthorization, initialized and startupdatinglocation and startupdatingheading but for no apparent reason, iOS events are simply not getting called.  
Neither didchangeauthorizationstatus; didupdateheading; nor didupdatelocations get called ever.  
What am I doing wrong?
