ios 解码 CLLocationAccuracy const 的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3411629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Decoding the CLLocationAccuracy const's
提问by dave
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.
以下列在 CLLocation.h 中,但根据我的经验,它们是在欺骗名称 - 最初可能认为有两个目的,1. 测试返回的位置的准确性,但也 2. 设置位置管理器的工作难度,特别是启用了什么(gps(有多少卫星频道)、wifi 工作的难易程度、三角测量等。
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.
我很想看看 CLLocation.m,但因为这不太可能很快发生 - 有没有人有任何现场测试表明他们认为这些不同模式正在发生什么。
ie, kCLLocationAccuracyBest = 10 satellite (channels/trunks?), 100% power to wifi etc..
即,kCLLocationAccuracyBest = 10 颗卫星(频道/中继?),100% 的 wifi 功率等。
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
我真正想知道的是,与kCLLocationAccuracyThreeKilometers
电池消耗有关的实际情况是什么 - 是否打开了 GPS?1 坐行李箱?wifi开启了吗?定时器上的wifi?谁知道?我知道我愿意
回答by Andrew Little
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?".
我同意 Olie 的观点,隐藏算法的细节是为了保护应用程序开发人员不必担心如何确定位置。也就是说,我认为提出这个问题仍然是合理的:“我的精度选择对功率有什么影响?”。
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.
我有一些信息可以指导您决定使用哪个,但我不知道 Apple 实施的真实细节。
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.
首先,假设随着读数变得更加准确,系统将需要使用更多耗电的无线电。例如,GPS 需要最详细的读数,在 100 米内,并且它使用最多的功率。
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;
- GPS - kCLLocationAccuracyBest;
- GPS - kCLLocationAccuracyNearestTenMeters;
- WiFi (or GPS in rural area) - kCLLocationAccuracyHundredMeters;
- Cell Tower - kCLLocationAccuracyKilometer;
- Cell Tower - kCLLocationAccuracyThreeKilometers;
- GPS - kCLLocationAccuracyBestForNavigation;
- GPS - kCLLocationAccuracyBest;
- GPS - kCLLocationAccuracyNearestTenMeters;
- WiFi(或农村地区的 GPS) - kCLLocationAccuracyHundredMeters;
- 蜂窝塔 - kCLLocationAccuracyKilometer;
- 蜂窝塔 - kCLLocationAccuracyThreeKilometers;
When choosing, it is recommended by Apple that you select the most coarse-grained accuracy that your application can afford.
在选择时,Apple 建议您选择您的应用程序可以承受的最粗粒度的精度。
Hope that helps, a.little.
希望有帮助,一点点。
回答by Abhi Beckert
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.
在大城市的商业区,wifi和手机塔三角都很好。住宅郊区,他们不是那么好。在农村地区,即使他们工作,他们也几乎没有工作。
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.
GPS 在室内不能很好地工作,并且在没有蜂窝塔帮助的情况下可能需要很长时间才能获得任何修复(可能需要 20 分钟!!)。卫星需要很长时间才能广播足够的信息来确定您的位置,并且可能会丢失数据包(云、建筑物、树木、山脉等)。值得注意的是,一个合适的高端 GPS 会有一个篮球大小的天线,没有手持 GPS 可以获得完美的信号。
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.
即使在信号完美的户外,当您快速改变方向(例如在高速公路上或有风的道路上)时,GPS 也是不准确的。BestForNavigation 设置使用加速度计和陀螺仪来抵消这一点。
Currently, the iOS platform uses:
目前,iOS平台使用:
- 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.
- GPS:非常准确,但耗电量大、速度慢且不总是可用。有些硬件没有 GPS。
- WiFi:大量耗电,仅适用于城市。也可能完全错误(例如,将您置于错误的城市)
- 手机塔:几乎完全没有电力消耗,在城市中运行良好。在农村不是那么好。在某些硬件上不存在。
- 加速度计:对其他位置修复略有改进,但功耗很大。
- 陀螺仪:对其他位置修复略有改进,但功耗很大。仅限 iPhone 4。
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.
你给它一个你需要的米精度(常数只是米的好名字),它会使用上述的组合,以最快的速度修复和尽可能低的功耗为你获得那个精度水平。它使用的技术会从一个用户到另一个用户而变化,并且会根据用户当时所处的世界位置而变化。
回答by Olie
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.
使用 extern 而不是公开实际发生的事情的全部意义在于,under-gerwerkkins 可以更改,并且您的代码不必担心它来获取改进。
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.
也就是说,CLLocationAccuracy 是 typedef-ed 加倍,所以我认为可以公平地猜测 kCLLocationAccuracyNearestTenMeters = 10.0、kCLLocationAccuracyHundredMeters = 100.0 等。Best 可能是 0、1 或 kCLLocationAccuracyNearestTenMeters,可能是他们对 BestTenMeters 的帮助像 TomTom 等。
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.
我不相信卫星数量或 wifi 功率会根据您所需的精度而改变。我理解算法的方式是,有一个近似计算,循环次数越多,它就越准确。因此,不太准确的只是更早地保释。
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.
但是,更重要的一点是:没关系。Apple 没有具体描述幕后发生的事情,因为那不是设计的一部分。设计是:如果你使用 kCLLocationAccuracyKilometer,你会得到一公里以内的答案,等等。Apple 现在可以自由改变他们的到达方式,而无需你关心。这种隔离是面向对象编程的基本原则。
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.
更正——我刚刚在现场观看 WWDC 会议(第 115 场会议),大约在 22:00 左右,他谈到了如何在使用 BestForNavigation 时增加一些陀螺仪校正(如果可用)。但是,他警告说,虽然这是电力和 CPU 密集型的,并且应该只在必要时使用,就像逐向导航一样。
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.
我不确定我还能公开谈论多少,但是,如果您是注册开发人员,您可以从 iTunes-U 获得会话。
(This is WWDC-2010, btw.)
(这是 WWDC-2010,顺便说一句。)