8.4 C
New York
Thursday, November 28, 2024

ios – CoreLocation returning cached location as new and correct when underground


I am engaged on a Swift App that collects the situation of the consumer as they use it. Typically the consumer might be underground the place there is no such thing as a GPS/different location fixing sign out there. Thats superb and the app ought to merely not return a location on this case, however for some purpose it nonetheless is returning the final location repair that it acquired, though I’m attempting to filter these previous places out. Im utilizing this to feed an output that exhibits the situation (formatted) and that stays on the previous location though its been minutes for the reason that final succesful replace was. Apple Maps and Google Maps additionally nonetheless present the previous location as blue dots on the map (in order non cached (afaik)).

// Delegate methodology referred to as when location is up to date
    func locationManager(_ supervisor: CLLocationManager, didUpdateLocations places: [CLLocation]) {
        // Get the newest location
        guard let location = places.final else { return }

        // Outline a threshold for the situation age
        let maximumAge: TimeInterval = 15
        let now = Date()
        let isRecent = now.timeIntervalSince(location.timestamp) <= maximumAge
        let isAccurateHorizontal = location.horizontalAccuracy <= self.demandedAccuracy
        let isAccurateVertical = location.verticalAccuracy <= self.demandedAccuracy
        
        print("Uncooked: (location)")

        if isRecent && isAccurateHorizontal && isAccurateVertical {
            queryLocation(to: location, appendVisited: true)
            print(location)
            print("Filtered: (location)")
        }
    }

Above is the code that i’ve as my locationManager delegate. It filters out any places which might be older than 15 seconds in addition to any the place the accuracy (I am pondering horizontal could be sufficient however higher secure than sorry) is beneath a variable quantity set elsewhere. From working the app within the subway the place there’s clearly no correct location sign it confirmed extremely inaccurate (400m+) readings so I added the space filter however for some purpose even this is not sufficient to forestall this ghosting of the final places. Im pondering it could be inconceivable as a result of each Apple and Google Maps face the identical challenge seemingly however I do not perceive why as IMO the timestamp filter ought to forestall an excessive amount of caching.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles