【发布时间】:2012-01-05 09:53:25
【问题描述】:
这更像是一个理论问题而不是代码: 到目前为止我做了什么:
我的应用严重依赖位置跟踪。
我在大约 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;
}
【问题讨论】:
标签: iphone objective-c ios xcode