繁体   English   中英

坚持CLLocation

[英]Stuck on CLLocation

这更多的是理论上的问题,而不是代码:我到目前为止所做的事情:

我的应用在很大程度上取决于位置跟踪。

我在大约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

当您不使用真实的GPS信号时,将通过三角测量来获取位置,这绝对不是您想要的精度。 即使有很多WiFi或手机信号塔,精度仍然是几米,更像100到10。

您想要的精度只能通过GPS实现,有些情况下只能达到100米左右的精度。 这一切都取决于GPS信号质量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM