iPhone SDK:使用 GPS 跟踪用户位置
我有一些关于 CoreLocation 和 GPS 的问题。
首先,核心定位中是用什么方法来不断获取用户当前坐标的?应该以什么时间间隔检索这些内容?
其次,每次收到这些坐标时是否应该将其推入 NSMutableArray 中,以便坐标数组代表用户路径?
谢谢,只是想开始让我注意这个问题。
I have a few questions about CoreLocation and GPS.
First, what method in core location is used to continually get the users current coordinates? And at what interval should these be retrieved?
Second, should these coordinates be pushed into a NSMutableArray each time they are received, so that the array of coordinates will represent the users path?
Thanks, just wanting to get started getting me mind around this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一个非常简短的版本:
首先,在 .h 中采用
协议,然后#import
。然后在 .m 中:
每次 Core Location 有问题时,您的
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
方法都会被 ping 到对你说,这应该每隔几秒钟发生一次。这些 CLLocation 对象包含有关准确性的信息,因此您可以筛选该方法中的优点。请务必在某个时刻调用
[locationManager stopUpdatingLocation]
,然后调用[locationManager release]
!祝你好运,找到自己!
A very abbreviated version:
First, adopt the
<CLLocationManagerDelegate>
protocol in your .h, and#import <CoreLocation/CoreLocation.h>
.Then in .m go:
Your
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
method will get pinged every time Core Location has something to say to you, which should happen every few seconds. those CLLocation objects contain info about accuracy, so you can screen for good points in that method.Be sure to call
[locationManager stopUpdatingLocation]
and then[locationManager release]
at some point!Good luck finding yourself!
最好的方法是阅读 CLLocationManager 类参考,它链接到几个示例项目。简短版本:
delegate
属性设置为将接收位置更新的类。CLLocationManagerDelegate
协议。The best way to is read the CLLocationManager Class Reference, which links to several example projects. The short version:
delegate
property to a class that will receive location updates.CLLocationManagerDelegate
protocol in the delegate.您可以定义可接受的准确度范围以及您希望接收自动更新的频率(基于距最后点机制的距离)。您也可以关闭位置管理器,然后通过使用计时器随意将其重新打开。
至于保存构建路径的位置,就没那么简单了。首先,您将不断获得 GPS 位置,直到达到所需的精度,并且对于未来的任何点,在获得良好位置之前,您可能会获得多个不准确的位置。因此,构建这些点的列表基本上只是它们的路径列表,以及许多额外的点。
您可以通过仅保存那些具有您想要的准确性的点来解决这个问题,但在这方面它是一个不完美的世界。
最好的情况是,我建议您保留两个列表,一个是路径,另一个是您正在比较的位置的运行列表,直到获得高度准确的位置,然后将其放入路径列表中。
一些示例项目按照这些思路做事,请检查一下。
You are able to define what range is acceptable for accuracy as well as how often you wish to receive automatic updates (based on a distance from last point mechanism). Also you can just turn off the location manager and turn it back on at will thru some use of a timer.
As for saving the locations to build a path, its not that simple. You will continually get GPS locations at first until the desired accuracy is achieved, and for any points in the future you may get more than one that is inaccurate before you get a good location. So building a list of these points will basically just be a list of their path, along with a lot of extra points.
You could solve this by saving only those points that have the accuracy you desire, but its an imperfect world in this respect.
Best case I would suggest you keep two lists, one is the path and the other is a running list of locations where you are comparing until you get a highly accurate location, then putting that on your path list.
Some of the example projects do things along these lines, do check them out.
您必须执行以下操作:
You will have to do the following: