iPhone SDK:使用 GPS 跟踪用户位置

发布于 2024-09-02 00:13:58 字数 175 浏览 5 评论 0原文

我有一些关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

给我一枪 2024-09-09 00:13:58

一个非常简短的版本:

首先,在 .h 中采用 协议,然后 #import

然后在 .m 中:

- (void)viewDidLoad {
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}


-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    CLLocationCoordinate2D here =  newLocation.coordinate;
    NSLog(@"%f  %f ", here.latitude, here.longitude);
}

每次 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:

- (void)viewDidLoad {
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}


-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    CLLocationCoordinate2D here =  newLocation.coordinate;
    NSLog(@"%f  %f ", here.latitude, here.longitude);
}

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!

×纯※雪 2024-09-09 00:13:58

最好的方法是阅读 CLLocationManager 类参考,它链接到几个示例项目。简短版本:

  1. delegate 属性设置为将接收位置更新的类。
  2. 实现 委托中的CLLocationManagerDelegate协议。
  3. 调用适当的方法来开始更新位置和/或航向。

The best way to is read the CLLocationManager Class Reference, which links to several example projects. The short version:

  1. Set the delegate property to a class that will receive location updates.
  2. Implement the CLLocationManagerDelegate protocol in the delegate.
  3. Call the appopriate methods to start updating location and/or heading.
老娘不死你永远是小三 2024-09-09 00:13:58

您可以定义可接受的准确度范围以及您希望接收自动更新的频率(基于距最后点机制的距离)。您也可以关闭位置管理器,然后通过使用计时器随意将其重新打开。

至于保存构建路径的位置,就没那么简单了。首先,您将不断获得 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.

梦回梦里 2024-09-09 00:13:58

您必须执行以下操作:

  1. 如果设备无法访问互联网
    1. 从 GPS 设备获取坐标
    2. 通过短信发送这些坐标
    3. 在您必须配置为从设备接收信息的 SMS 网关上接收和解码 SMS 消息。
    4. 更新应用程序数据库或您正在使用的任何其他商店的信息
    5. 使用最新信息更新地图上的位置
  2. 如果设备可以访问互联网
    1. 从 GPS 设备获取坐标
    2. 连接到应用服务器(可能是某些服务)并上传信息
    3. 更新应用程序数据库或您正在使用的任何其他商店的信息
    4. 使用最新信息更新地图上的位置

You will have to do the following:

  1. If device cannot access internet
    1. Get co-ordinates from GPS device
    2. Send these co-ordinates via SMS
    3. Receive and decode SMS message at the SMS gateway you have to configure to receive info from device.
    4. Update the info on the application database or any other store you are using
    5. Update the position on map with latest info
  2. If device can access internet
    1. Get co-ordinates from GPS device
    2. Connect to application server (may be some service) and upload information
    3. Update the info on the application database or any other store you are using
    4. Update the position on map with latest info
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文