Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Location Accuracy

Hello i am using location in iOS app i set the accuracy like this:

 locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters

and i am using this function to check the accuracy

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    print(manager.location!.horizontalAccuracy)

    if locations.last!.horizontalAccuracy <= manager.desiredAccuracy{
        print(manager.location)
        location = locations.last!
        locationManager.stopUpdatingLocation()
        locationManager = nil           
    }
}

The problem is that the accuracy stack to 1414 and never goes to 100. Is there any way to fix that problem?

like image 789
Panayiotis Irakleous Avatar asked Mar 14 '23 19:03

Panayiotis Irakleous


2 Answers

It's a limitation of the hardware, possible combined with your particular location. If you are indoors writing your code then GPS isn't going to work (try walking to a window), so you rely on WiFi which might just have very bad accuracy where you are, or on cell towers which isn't very accurate anywhere.

like image 148
gnasher729 Avatar answered Mar 31 '23 02:03

gnasher729


iOS uses multiple hardware options to determine location: cell tower, wifi access points, gps. The options are listed in increasing accuracy AND power consumption order.

iOS uses desiredAccuracy as a hint of which hardware it should engage to serve your request, and the OS will try to avoid activating the hardware it believes is unnecessary in order to achieve the desired accuracy.

I believe Apple does not offer any specifics as to what the threshold values are.

It looks like in your case iOS does not engage WiFi AP hardware (or might be unable to connect to a server to access the AP database, or there is not enough known APs around you), thus all location readings you get are from cell tower triangulation.

You may want to either

  • request higher accuracy than you need, but stop updates as soon as you get required accuracy, or
  • (assuming iOS9) use the new requestLocation() method, which is at least more battery-friendly, and at most might try to make more intelligent decisions on what hardware to activate - note I did not test the "at most" assumption, would be interested to learn if it is correct.

Also, this is not in the books, but you can tell if location reading is from GPS by looking at speed value, if it is invalid (less than zero), it is NOT GPS location.

Hope this helps, -- Alex

like image 38
Alex Pavlov Avatar answered Mar 31 '23 04:03

Alex Pavlov