这更多是理论上的问题,而不是代码:
我到目前为止所做的:
我的应用严重依赖于位置跟踪。
我在大约5个小时后发布了一个有关该问题的问题,但没有合适的答案,现在在这里放一个新问题已经很老了。在我得到这个问题的答案之后,我会关闭它。
我想要做的是有一个用户按下的按钮。它使位置管理器开始更新位置,然后每移动5英尺。我想让iPhone播放随机声音。
我执行了下面给出的正确代码,现在我在设备上进行了测试,该设备从一处移动到我家中的此处。通过反复试验,我知道iPhone最初的几个位置都试图获得准确的结果,通常应该避免使用,因此我把处理位置作为条件,条件是在超过2秒后才返回位置。
现在我的真实问题:
我将设备放在wifi上。(没有gps,也没有gps),因此经过几次最初无用的位置更新之后。我的警报停止显示..我当时想:为什么不起作用。我将其设置为最佳准确性。没有过滤到1.5米..我在房子里移动得像15英尺,没有更新吗?。现在我认为这是因为它通过wifi进行定位,因此即使我绕着它移动了40条馈源,也没有找到新的位置无线上网。?我对么?
如果是这样..谁能告诉我这将以gps ..为美国用户..他们那里有很多塔楼..以便我的应用正确更新新位置,使其与以前的位置至少相距5米。 ..
很抱歉,这个问题很长..我有太多疑问。
-(id) init
{
if(self = [super init])
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
// locationManager.distanceFilter = 1.5;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
return self;
}
return nil;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New Lcoation"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
self.currentLocation = newLocation;
BOOL newLocationIsValid = [self isValidLocation:newLocation withOldLocation:oldLocation];
if(newLocationIsValid && oldLocation)
{
int distance = [newLocation distanceFromLocation:oldLocation];
if(distance >2 && distance <10)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Distance"
message:[NSString stringWithFormat:@"%i meters",distance]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[fileURl release];
}
}
}
-(BOOL)isValidLocation:(CLLocation*)newLocation withOldLocation:(CLLocation*)oldLocation
{
if(newLocation.horizontalAccuracy < 0 )
{
return NO;
}
NSTimeInterval secondsSinceLastPoint = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
if(secondsSinceLastPoint < 0)
{
return NO;
}
if(secondsSinceLastPoint < 2)
{
int distance = [newLocation distanceFromLocation:oldLocation];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Distance"
message:[NSString stringWithFormat:@"%i meters",distance]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return NO;
}
return YES;
}
最佳答案
是的,不起作用,因为您使用wifi进行定位。定位服务只知道您的wifi在哪里,而不是您相对于wifi的位置(那很好)。
因此,为您提供服务,您必须使用gps。即使这样,准确性也无法保证。
见http://www.kowoma.de/en/gps/accuracy.htm
关于iphone - 卡在CLLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8740488/