gpt4 book ai didi

iphone - 确定从 iPhone CoreLocation 返回的最准确的最终算法?

转载 作者:行者123 更新时间:2023-12-03 18:36:19 26 4
gpt4 key购买 nike

有人已经解决这个问题了吗?我读了很多论坛帖子,但我仍然无法判断这是否是一个已解决的问题......

鉴于 didUpdateToLocation() 可能返回缓存或不准确的信息,您如何判断何时获得了准确的修复?

当您将所需精度设置为 kCLLocationAccuracyNearestTenMeters、HundredMeters、Kilometer、ThreeKilometers 时,显然您可以将返回点的水平精度与所需精度进行比较,以决定何时接受点。

但是 kCLLocationAccuracyBestForNavigation 和 kCLLocationAccuracyBest 的值分别为 -2 和 -1,那么我如何知道何时达到所需的精度?

我目前检查修复的期限并拒绝任何在时间上太“旧”的修复。然后我检查水平精度是否为负,如果是则拒绝。如果我得到正的垂直精度,那么我通常会使用该修复,因为相应的水平精度也很好。

但是当我寻找 10-100 米的精度时,使用了这些检查......我不知道当我运行 ...AccuracyBestForNavigation 或 ...AccuracyBest 时需要检查什么?我是否应该让 locationManager 不断运行并且永远不要期望关闭它并且不过滤任何结果??

有比我聪明的人来回答吗?

谢谢

最佳答案

这并不是一个真正确定的、完美的算法(我怀疑是否有一个算法可以完成这项任务,因为外部条件,我的意思是,你可以尝试在平原上或坟墓内获取你的位置),它是一个临时算法,它对我有用。

我为 LocationManager 做了一个包装,例如

@protocol LocationManagerWrapperDelegate <NSObject>

@required

- (void) locationUpdated: (CLLocation *) locationUpdate;
- (void) errorOccured: (NSError *) error;

@end

@interface LocationManagerWrapper : NSObject <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
id delegate;
CLLocation *mostAccurateLocation;
int updatesCounter;
BOOL m_acceptableTimePeriodElapsed;
}

@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocation *mostAccurateLocation;
@property (nonatomic, assign) id <LocationManagerWrapperDelegate> delegate;

- (void) startUpdatingLocation;

- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation;

- (void) locationManager: (CLLocationManager *) manager
didFailWithError: (NSError *) error;

+ (LocationManagerWrapper *) sharedInstance;

@end

实现

#define NUMBER_OF_TRIES 4   
#define ACCEPTABLE_TIME_PERIOD 15.0

- (void) startUpdatingLocation
{
NSAssert(self.delegate != nil, @"No delegate set to receive location update.");

updatesCounter = 0;
self.mostAccurateLocation = nil;
m_acceptableTimePeriodElapsed = NO;
[NSTimer scheduledTimerWithTimeInterval:ACCEPTABLE_TIME_PERIOD
target:self
selector:@selector(acceptableTimePeriodElapsed:)
userInfo:nil
repeats:NO];
[self.locationManager startUpdatingLocation];
}

- (void) acceptableTimePeriodElapsed: (NSTimer *) timer
{
@synchronized(self)
{
m_acceptableTimePeriodElapsed = YES;
// TODO: if period is set by user - check we have mostAccurateLocation at this point
[self.delegate locationUpdated:self.mostAccurateLocation];
[self.locationManager stopUpdatingLocation];
}
}

- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation
{
@synchronized(self)
{
if (m_acceptableTimePeriodElapsed) return;
NSLog([NSString stringWithFormat:@"lat: %@, long: %@, acc: %@",
[ [NSNumber numberWithDouble:newLocation.coordinate.latitude] stringValue],
[ [NSNumber numberWithDouble:newLocation.coordinate.longitude] stringValue],
[ [NSNumber numberWithDouble:newLocation.horizontalAccuracy] stringValue] ] );

updatesCounter++;
// ignore first returned value
if (updatesCounter <= 1) return;
if (self.mostAccurateLocation == nil ||
self.mostAccurateLocation.horizontalAccuracy > newLocation.horizontalAccuracy)
{
self.mostAccurateLocation = newLocation;
}
if (updatesCounter >= NUMBER_OF_TRIES)
{
[self.delegate locationUpdated:self.mostAccurateLocation];
[self.locationManager stopUpdatingLocation];
}
}
}

代码不是很好(格式也不是),但我认为这个想法很简单明了,获取第一个位置,扔掉它,它是一个缓存的位置,最多尝试 3 次以获得最准确的位置。它可能需要很长时间,如果用户正在等待(如我的情况),请定义一个时间限制。再一次,它适用于我的应用程序,但请随意调整它或采取另一种方法。

关于iphone - 确定从 iPhone CoreLocation 返回的最准确的最终算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3877370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com