【问题标题】:Iphone GPS is not giving accurate latitude and longitudeIphone GPS 无法提供准确的经纬度
【发布时间】:2012-09-20 17:26:29
【问题描述】:

你好朋友,我看过很多关于 GPS 精度问题的帖子,但它始终无法正常工作

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

    NSString  *latstr = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
    NSString  *longstring=[NSStringstringWithFormat:@"%f",newLocation.coordinate.longitude];

     if (abs(howRecent)>5.0)
     {
         [self.locationManager startUpdatingLocation];
         return;
      }
    if(abs(newLocation.horizontalAccuracy)<0.0f)
    {
        [self.locationManager startUpdatingLocation];
        return;
    }
    if(newLocation.horizontalAccuracy>65.0f)
    {
        [self.locationManager startUpdatingLocation];
        return;
    }
    self.latstring = [latstr copy];
    self.longstr = [longstring copy];

    if((updateLocationFirst||loadFirstView))
    {    
        [[NSUserDefaults standardUserDefaults]setObject:latstring forKey:@"Latitude"];
        [[NSUserDefaults standardUserDefaults]setObject:longstr forKey:@"Longitude"];
        [self displayParticularDaySpecial];
        loadFirstView=FALSE;
        updateLocationFirst=FALSE;
        [self.locationManager stopUpdatingLocation];
    }
}

这里的问题是,如果我要降低精度值,它需要花费大量时间来加载,并且当您到达目的地时这个值有问题,那么我正在将一些地址的纬度和经度发送到 Google到目的地相差 0.6 英里。

【问题讨论】:

  • 顺便说一句,abs(newLocation.horizontalAccuracy)&lt;0.0f 永远不会是真的,不是吗?一个数的绝对值怎么会小于零?

标签: iphone ios cllocationmanager


【解决方案1】:

您应该参考Location Awareness Programming Guide,它为确定您的位置提供了出色的编程示例。

正如您将在该文档的演示中看到的那样,当您start the standard location manager 时,您通常会告诉它您需要什么精度。一旦您启动位置管理器,您就不必再次启动它(就像您在代码示例中所做的那样)。 didUpdateLocations 方法将被一次又一次地调用,准确度越来越高,这一切都是靠自己的。您无需再次启动位置管理器……它会一直运行,直到您将其关闭。根据定义,如果您在didUpdateLocations 中,则表示它已经开启。

我还注意到您使用的是旧的didUpdateToLocation。如果你正在为 iOS 6 编程,你真的想使用 didUpdateLocations,这是 CLLocationManagerDelegate 方法的当前版本。

最后,您提到获取您的位置需要很长时间。这是很有可能的。事实上,在某些区域,你永远不会离得很近(或任何位置)。你的应用应该假设准确的位置需要一段时间,如果你从来没有得到一个真正准确的位置,你应该优雅地处理,这是很有可能的。

【讨论】:

    【解决方案2】:

    您是否在 CLLocationManager 中设置了 desiredLocationAccuracy?默认情况下,范围有点宽。

    获得一个非常准确的值需要一些时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      相关资源
      最近更新 更多