iPhone SDK:使用GPS跟踪用户位置 [英] iPhone SDK: Track users location using GPS

查看:182
本文介绍了iPhone SDK:使用GPS跟踪用户位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些关于CoreLocation和GPS的问题。

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?

其次,每次接收这些坐标时都应将它们推入NSMutableArray,以便坐标数组代表用户路径?

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.

推荐答案

一个非常简短的版本:

首先,在你的版本中采用< CLLocationManagerDelegate> 协议。 h,和 #import< CoreLocation / CoreLocation.h>

First, adopt the <CLLocationManagerDelegate> protocol in your .h, and #import <CoreLocation/CoreLocation.h>.

然后在.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);
}

您的 - (void)locationManager:(CLLocationManager *管理器didUpdateToLocation :( CLLocation *)newLocation fromLocation :( CLLocation *)oldLocation 方法将在每次Core Location对你说话时得到ping,这应该每隔几秒发生一次。这些CLLocation对象包含有关准确性的信息,因此您可以在该方法中筛选好点。

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.

请务必调用 [locationManager stopUpdatingLocation] 然后 [locationManager发布] 在某些时候!

Be sure to call [locationManager stopUpdatingLocation] and then [locationManager release] at some point!

祝你好运!

这篇关于iPhone SDK:使用GPS跟踪用户位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆