【发布时间】:2011-09-05 19:58:29
【问题描述】:
我有一个 MKMapView,每次加载视图或调用 showLocation 自定义类方法时,我都会删除一个注释。
我需要准确度是最好的
-(void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
}
-(IBAction) showLocation:(id) sender{
[locationManager startUpdatingLocation];
}
- (void) locationManager:(CLLocationManager *) manager
didUpdateToLocation:(CLLocation *) newLocation
fromLocation:(CLLocation *) oldLocation {
// start geocoding with newLocation coordinate which will automatically set annotation.
SVGeocoder *geocodeRequest = [[SVGeocoder alloc]
initWithCoordinate:CLLocationCoordinate2DMake(newLocation.coordinate.latitude, newLocation.coordinate.longitude)];
[geocodeRequest setDelegate:self];
[geocodeRequest startAsynchronous];
[geocodeRequest release];
[locationManager stopUpdatingLocation];
}
我的问题是什么时候会调用didUpdateToLocation 方法?只有在我执行[locationManager startUpdatingLocation]时找到新位置后?
当用户在旅行和静止不动时,我遇到了一些奇怪的问题。 假设用户从点 A->B->C->D 出发,点之间有 1 分钟的间隔。当我在 C 点调用我的方法时,它有时会返回 A 点的坐标,有时会返回 B 点,有时会返回 C。这只是随机的。
当我静止不动时,情况就更奇怪了。当我调用 showLocation 方法时,我得到不同的坐标,即使我连接到我家的 WiFi。
我正在考虑实施 didUpdateToLocation 以在 5 秒内获得最佳结果。如果在 5 秒内,它找到了我定义的精度的特定位置,则使用坐标。如果没有,请使用它在 5 秒时间范围内找到的最佳值。但由于我是新手,我不确定如何编写这样的代码。我阅读了 NSTimer,它似乎可以工作。
各位有什么建议吗?
提前非常感谢!
【问题讨论】:
标签: iphone ios cllocationmanager