首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >卡住在CLLocation上

卡住在CLLocation上
EN

Stack Overflow用户
提问于 2012-01-05 17:53:25
回答 2查看 294关注 0票数 1

这更多的是一个理论问题,而不是代码:我到目前为止做了什么:

我的应用很大程度上依赖于位置跟踪。

我在大约5个小时前发布了一个问题,但没有合适的答案,现在在那里放一个新问题已经很老了,.i将在我得到这个问题的答案后关闭它。

我想做的是有一个按钮,用户presses.it使位置管理器开始更新位置,然后为每5英尺移动。我想让iPhone播放随机的声音。我实现了下面给出的正确代码,现在我在我的设备上进行了测试,从一个地方搬到了我家的这里。通过试验和错误,我知道最初的几个位置是iPhone,试图获得准确的结果,通常是要避免的,所以我将其作为处理位置的条件,这些位置比之前的位置晚2秒。

现在我真正的问题是:我有我的设备在wifi上。(没有gps,也不能有)所以在最初几次无用的位置更新之后。我的警报停止显示..我想:为什么不起作用。我将其设置为最准确。过滤到1.5米..我在房子里移动了大约15英尺,没有更新?..now,我想这是因为它通过wifi获取位置,因此即使我在wifi周围移动40个feeds,它也没有创建新的位置。我说的对吗?

如果这是真的..谁能告诉我这在gps里能正常工作吗?对于美国的users..where,他们有很多塔..这样我的应用程序才能正确地更新新位置,新位置距离之前的位置至少有5米远。

很抱歉问了这么长的问题..对我来说有太多的疑问..

代码语言:javascript
复制
-(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;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-01-05 18:06:20

是的,不起作用,因为你使用wifi进行定位。定位服务只知道你的wifi在哪里,而不是你相对于wifi的位置(那就好了)。

所以你的服务必须使用全球定位系统。即使这样,准确度也不能保证。

请参阅http://www.kowoma.de/en/gps/accuracy.htm

票数 2
EN

Stack Overflow用户

发布于 2012-01-05 18:05:36

当你不使用真实的GPS信号时,位置是通过三角测量来恢复的,这绝不是你想要的接近精度。即使有许多WiFi或手机发射塔,精度仍然是几米,更像是100而不是10。

你想要的精度只能用GPS来实现,在某些情况下只能有100米左右的精度。这完全取决于GPS信号质量。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8740488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档