CLLocation返回负速度 [英] CLLocation returning negative speed

查看:304
本文介绍了CLLocation返回负速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的问题是试图让当前的速度总是返回一个负值,我已经把我的iPhone和我一起带到一个良好的3G信号的地方,并没有关系,location.speed的值始终是-1。这里是代码事情:

$ $ p $ #define kRequiredAccuracy 1500.0 //米
#define kMaxAge 60.0 //秒
code>

在init方法中:

  self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

然后doUpdateToLocation:

 (CLLocation *)oldLocation fromLocation:(CLLocation *)oldLocation {

NSTimeInterval ageInSeconds = [newLocation.timestamp timeIntervalSinceNow];
NSLog(@Location:%@,[newLocation description]);

if(newLocation.horizo​​ntalAccuracy> kRequiredAccuracy || fabs(ageInSeconds)> kMaxAge)
{
NSLog(@unsurate position);
[self.delegate inacuratePosition];

}
else {

[self.delegate locationUpdate:newLocation andOldLocation:oldLocation];
location = newLocation.coordinate;如果(追踪)
{
[self updatePosition];





$ b}
if(firstTime)
{
[self placeStartMark];
firstTime = FALSE;
}



}

最后在我实现协议的视图控制器中:

   - (void)locationUpdate:(CLLocation *) newLocation和OldLocation:(CLLocation *)oldLocation {

double speed = [newLocation speed] * 3.6;



双高度= [newLocation altitude];
[self checkMaxSpeedAndAltitude:speed:altitude];
if(速度<0)
速度= 0;



locationLabel.text = [NSString stringWithFormat:@speed:%f km / h altitude:%f m,speed,altitude];
}

我疯了,所以如果有人知道任何解决方案,它肯定会有帮助。
谢谢

解决方案

通常情况下,如果使用的位置检测机制不支持,则会得到负高度和速度。例如,当使用Wi-Fi或小区三角测量时。你确定,你正在获得GPS更新,那么你在自由空间下进行测试?即使到那时,您仍然会收到WiFi和手机信号塔位置更新,因此您必须将其过滤掉。



Wi-Fi位置更新通常需要65米的水平精度。


I'm starting a new app which uses the coreLocation and the mapkit frameworks.

My problem is trying to get the current speed always returns me a negative value, i have take my iPhone with me to places with a good 3g signal and it doesn't matter, location.speed value is always -1.

here is the code which matters:

#define kRequiredAccuracy 1500.0 //meters
#define kMaxAge 60.0 //seconds

in the init method:

self.locationManager=[[CLLocationManager alloc] init];
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;

then didUpdateToLocation:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

    NSTimeInterval ageInSeconds = [newLocation.timestamp timeIntervalSinceNow];
    NSLog(@"Location: %@", [newLocation description]);

    if( newLocation.horizontalAccuracy > kRequiredAccuracy || fabs(ageInSeconds) > kMaxAge )
    {
        NSLog(@"inacurate position");
        [self.delegate inacuratePosition];

    }
    else {

    [self.delegate locationUpdate:newLocation andOldLocation:oldLocation];
    location=newLocation.coordinate;


    }


    if(tracking)
    {   
    [self updatePosition];
    }
    if(firstTime)
    {
        [self placeStartMark];
        firstTime=FALSE;
    }



}

and finally in the view controller in which I'm implementing the protocol:

- (void)locationUpdate:(CLLocation *)newLocation andOldLocation:(CLLocation*)oldLocation{

    double speed = [newLocation speed] *3.6;



    double altitude= [newLocation altitude];
    [self checkMaxSpeedAndAltitude:speed :altitude];
    if(speed< 0)
        speed=0;



    locationLabel.text=[NSString stringWithFormat:@"speed: %f km/h   altitude: %f m", speed,altitude];
}

Im getting crazy so if anyone knows any solution it will be helpful for sure. Thanks

解决方案

Usually, you get negative altitude and speed if the used location detection mechanism doesn't support it. For instance, when Wi-Fi or cell triangulation is used. Are you sure, you're getting GPS updates, so are you testing under the free sky? Even then, you'll still receive WiFi and cell tower location updates so you've to filter them out.

65 m horizontal accuracy is typical for Wi-Fi location updates.

这篇关于CLLocation返回负速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆