这更像是一个理论问题,而不是代码: 我到现在为止做了什么:
我的应用程序严重依赖于位置跟踪。
我在5个小时左右发布了一个关于它的问题而没有合适的答案,现在提出一个新问题已经很老了。我会在得到这个问题的答案后关闭它。
我想要做的是有一个用户按下的按钮。它使位置管理器开始更新位置,然后每移动5英尺。我想让iPhone播放随机声音。 我实现了下面给出的正确代码,现在我在我的设备上测试从一个地方移动到我家里的这里。通过试验和错误我知道,前几个地方是iPhone试图获得准确的结果,并且通常是要避免,所以我做了一个条件处理位置,超过2秒后到达。
现在我的真实问题: 我有我的设备在wifi上。(没有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;
}
答案 0 :(得分:2)
是的,因为您使用wifi进行定位而无法正常工作。位置服务只知道您的无线网络的位置,而不是相对于您的无线网络的位置(这将是不错的。)
因此,对于您的服务,您必须使用gps。即使这样,准确性也不会保证。
答案 1 :(得分:1)
当您不使用真实GPS信号时,通过三角测量检索位置,这绝不是您想要的准确度。即使有很多WiFi或手机信号塔,精度仍然只有几米,更像100到10。
您想要的准确度只能通过GPS实现,有些情况下只能达到100米左右的精度。这一切都取决于GPS信号质量。