Decoding the CLLocationAccuracy const's
Asked Answered
S

3

32

the following are listed in CLLocation.h but from my experience they are deceiving names- possibly originally thought up to serve two purposes, 1. to test the accuracy of the location returned, but also 2. to set how hard the location manager works, specifically what is enabled (gps (how many sat channels), how hard the wifi works, triangulation etc.

extern const CLLocationAccuracy kCLLocationAccuracyBestForNavigation; // (raw value: -2)
extern const CLLocationAccuracy kCLLocationAccuracyBest; // (raw value: -1)
extern const CLLocationAccuracy kCLLocationAccuracyNearestTenMeters; // (raw value: 10)
extern const CLLocationAccuracy kCLLocationAccuracyHundredMeters; // (raw value: 100)
extern const CLLocationAccuracy kCLLocationAccuracyKilometer; // (raw value: 1000)
extern const CLLocationAccuracy kCLLocationAccuracyThreeKilometers; // (raw value: 3000)

I would love to take a look at CLLocation.m, but as that is not likely to happen any time soon- does anyone have any field testing showing what they think is going on with these different modes.

ie, kCLLocationAccuracyBest = 10 satellite (channels/trunks?), 100% power to wifi etc..

I'm kind of guessing at straws here- I think this is the type of information apple should have provided-

what I really want to know is, what is actually happening with kCLLocationAccuracyThreeKilometers in relation to battery draw- is the gps on? 1 sat trunk? wifi enabled? wifi on a timer? who knows? I know I'd like to

Stockyard answered 5/8, 2010 at 3:53 Comment(0)
E
59

I agree with Olie that hiding the details of the algorithm is intended to protect the app developer from worrying about how location is determined. That said, I believe it's still reasonable to ask the question: "what are the power implications of my accuracy selection?".

I have a little bit of information that might guide your decision on which to use, but I don't know the true details of Apple's implementation.

First, assume that as the reading becomes more accurate, the system will need to use more power-hungry radios. For example, the GPS will be required for the most detailed readings, inside 100 Meters, and it uses the most power.

Here is an educated guess at the mechanism used to determine the accuracy. List is ordered with (1) being the highest battery drain.

  1. GPS - kCLLocationAccuracyBestForNavigation;
  2. GPS - kCLLocationAccuracyBest;
  3. GPS - kCLLocationAccuracyNearestTenMeters;
  4. WiFi (or GPS in rural area) - kCLLocationAccuracyHundredMeters;
  5. Cell Tower - kCLLocationAccuracyKilometer;
  6. Cell Tower - kCLLocationAccuracyThreeKilometers;

When choosing, it is recommended by Apple that you select the most coarse-grained accuracy that your application can afford.

Hope that helps, a.little.

Epicurean answered 11/8, 2010 at 16:33 Comment(8)
Per Apples Documentation: kCLLocationAccuracyBestForNavigation Use the highest possible accuracy and combine it with additional sensor data. This level of accuracy is intended for use in navigation applications that require precise position information at all times and are intended to be used only while the device is plugged in. This is the only constant with any description pertaining to sensor/power usage.Governor
is kCLLocationAccuracyBestForNavigation gives better location points then kCLLocationAccuracyBest? does it forces you to be near a road? becasue most navigation programs are for driving/bus transport navigation. Can i get better location cordinates if i will use kCLLocationAccuracyBest instead of kCLLocationAccuracyBestForNavigation?Steiermark
I think it's safe to assume that even at it's worst, kCLLocationAccuracyBestForNavigation is as good as kCLLocationAccuracyBest.Glidebomb
@Andrew Little This is great description and this help me a lot . Thanks for this post. This saves my days.Pneumoconiosis
based on this research, your answer seems partially wrong. That is WiFi (or GPS in rural area) isn't for kCLLocationAccuracyHundredMeters, rather it's kCLLocationAccuracyNearestTenMeters. For kCLLocationAccuracyHundredMeters it's mainly wifi and cellTower.Headlock
As for the difference of kCLLocationAccuracyKilometer & kCLLocationAccuracyThreeKilometer I asked an expert he said It's likely a matter of how many towers to look into and how often to look for updates e.g. with kCLLocationAccuracyThreeKilometer we might be look into 1-2 tower every 5-6 minutes, but with kCLLocationAccuracyKilometer we might be look into 3-4 towers to get a better triangulation and check every 2 minutes so make sure we're not missing the 1km threshold. Likely the interval between checking are affected by speed, ie if you're going fast then it would check every 1-2 minutesHeadlock
What should I pick If I am building a speedometer app?Percival
Additionally when you're using cell towers then sometimes because the tower is busy, you might have to use a tower that is more distant to you. As a result your calculated location would be inaccurate because it wrongly thinks you're closer to the not-closer tower!Headlock
C
11

In the business district of a major city, wifi and cell tower triangulation are both very good. Residential suburbs they're not so good. In rural areas they barely work if they work at all.

GPS doesn't work very well indoors, and can take a very long time to get any fix at all without cell tower assistance (possibly 20 minutes!!). It takes that long for the satelites to broadcast enough information to determine your location, and there can be packet loss (clouds, buildings, trees, mountains, etc). It's worth noting that a proper high end GPS will have an antenna the size of a basket ball, no handheld GPS can get a perfect signal.

Even outdoors with perfect signal, GPS is inaccurate when you change direction rapidly (such as on the highway or a windy road). The BestForNavigation setting uses the accelerometer and gyroscope to offset this.

Currently, the iOS platform uses:

  • GPS: very accurate, but high power draw, slow and not always available. some hardware doesn't have a GPS.
  • WiFi: lots of power draw, and only works in the city. Can also be flat out wrong (eg place you in the wrong city)
  • Cell Tower: almost no power draw at all, and works well in the city. Not so great in rural areas. Doesn't exist on some hardware.
  • Accelerometer: slight improvements to other location fixes, but huge power draw.
  • Gyroscope: slight improvements to other location fixes, but huge power draw. iPhone 4 only.

You give it an accuracy in meters that you need (the constants are just nice names for meters), and it will use a combination of the above, to get you that level of accuracy with the fastest possible fix and lowest possible power draw. The technique it uses will change, from one user to another, and will change depending on where in the world the user is standing at the time.

Chadburn answered 11/4, 2011 at 3:59 Comment(5)
Whats the difference between high power draw, lots of power draw and huge power draw. lol.Sharika
@Sharika WiFi/GSM triangulation uses very little power. GPS uses a fair bit of power. GPS with Accelerator/Gyroscope correction requires a lot of math and makes the CPU work hard, so the power draw is extreme.Chadburn
> In the business district of a major city, wifi and cell tower triangulation are both very good. @Abhi Beckert , I'm not sure about that. For WiFi you are probably right, but I get pretty bad accuracy (hundreds of meters) inside buildings here in the East Village of Manhattan when WiFi has been turned off for a while. (I assume in this situation, cell towers are being used). I also got pretty bad accuracy in Downtown Seattle (over 1000 meters), inside buildings.Cyclothymia
@BrennanVincent I was mostly referring to shopping malls/train stations/etc that often have dozens of cell towers inside the building. Not all buildings have them, especially since some cell network frequencies can travel through walls effectively – eliminating any need for indoor cells. Also 1,000 metres is decent - in a rural area cell network triangulation can be as bad as 300,000 metre accuracy.Chadburn
if you're using something like: kCLLocationAccuracyHundredMeters ie using WiFi triangulation, then what happens when you're in a remote area? Would it fallback to GPS and drain battery or celltowers w/ degrading accuracy? And what do you mean by Cell Tower: almost no power draw at all, and works well in the city. Not so great in rural areas. Doesn't exist on some hardware. Do you mean not every cell tower has the hardware needed for triangulation?Headlock
W
2

The whole point of using extern rather than exposing what is actually happening is so that the under-gerwerkkins can change and your code doesn't have to worry about it to pick up the improvements.

That said, CLLocationAccuracy is typedef-ed to double, so I think it's fair to guess that kCLLocationAccuracyNearestTenMeters = 10.0, kCLLocationAccuracyHundredMeters = 100.0, etc. Best is likely either 0, 1 or kCLLocationAccuracyNearestTenMeters, and BestForNavigation is probably one they tossed it to help folks like TomTom, etc.

If you REALLY want to know, you can print out the values -- they're just doubles.

I do not believe that the number of satellites or power to wifi is altered based on your desired accuracy. The way I understand the algorithms, there is an approximation calculation that, the more times through the loop, the more accurate it gets. Hence, less-accurate just bails earlier.

But, again, the more important point is: it doesn't matter. Apple specifically doesn't describe what goes on behind the scenes because that's not part of the design. The design is: if you use kCLLocationAccuracyKilometer, you'll get an answer that's within a kilometer, etc. And Apple is now free to change how they arrive at that without you caring. This sort of isolation is a basic tenet of object oriented programming.

EDIT:

CORRECTION -- I'm just now watching the WWDC session on location (Session 115) and, at about 22:00 or so, he talks about how, when using BestForNavigation, this adds in some gyroscope correction (when available.) However, he warns that, while this is power & CPU intensive, and should be only used when necessary, as with turn-by-turn navigation.

I'm not sure how much more I can talk about this publically but, if you're a registered developer, you can get the sessions from iTunes-U.

(This is WWDC-2010, btw.)

Windgall answered 11/8, 2010 at 14:52 Comment(3)
Note, too, along with Little's comment, Mr. WWDC says that cell-tower only with no data connection (as when roaming without a data plan) is 10-50km accurate. "Similar to area code, vice a specific number, in terms of location."Windgall
I remember learning that kCLLocationAccuracyBest is actually -1, just fyi. Thanks for the answer.Grow
@Grow According to the offical docs developer.apple.com/library/mac/documentation/CoreLocation/… horizontalAccuracy: A negative value indicates that the location’s latitude and longitude are invalid.Formenti

© 2022 - 2024 — McMap. All rights reserved.