Search code examples
ioscore-locationcore-motion

Strange #NullIsland warning from CoreMotion.framework


Since recently, I get in the Xcode logs a lot of strange warnings from the CoreMotion framework, related to function getLocationForBundleID:

[Client] {"msg":"#NullIsland Either the latitude or longitude was exactly 0! That's highly unlikely", "latIsZero":0, "lonIsZero":0}  
[Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":'28 5B E0 D7 EB 7F 00 00'}  

I do not see any malfunction of my app. So maybe these logs can be ignored, but they are annoying anyway.

My questions are:

How can I correct a potential error?
How can I stop these warnings?


Solution

  • Apparently this error message is logged if property location of a CLLocationManager is read, before the CLLocationManager delivered the very first location.

    My solution is the following:
    I use anyway a subclass of CLLocationManager that allows me to set the location property for tests programmatically. This is done as follows:

    private var _location: CLLocation?
    @objc dynamic override var location: CLLocation? {
        get { 
            let usedLocation = _location ?? super.location // Here the error is logged if no location has been delivered yet
            return usedLocation 
        }
        set {
            _location = newValue
        }   
    }
    

    This subclass has now an additional property

      var anyLocationDelivered = false  
    

    that is set true in

        func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
            locationManager.anyLocationDelivered = true
        // …
      }  
    

    and the getter is now

    get { 
        guard anyLocationDelivered else { return nil }
        let usedLocation = _location ?? super.location
        return usedLocation 
    }  
    

    Now this error message is no longer logged.