使用CLLocationManager获取准确的位置(Getting an accurate location with CLLocationManager)

编程入门 行业动态 更新时间:2024-10-15 18:27:22
使用CLLocationManager获取准确的位置(Getting an accurate location with CLLocationManager)

我开始乱用CLLocationManager,我正在尝试使用下面的回调方法。 我去了外面在我的iPhone上测试它,并且在前几次更新时,我似乎正在得到一些乱码值,就像突然间我的距离是39米,即使我没有移动到任何地方。 或者有时它会从5开始,然后跳到20米,再次没有我移动到任何地方。 我走出去走了,从最初的起点看起来更新似乎是'好',然后当我回到原点时,我回到了原来的39米的起点。 我想知道我在下面做的是否正确。 我还包含了我的viewDidLoad方法,用于初始化我的CLLocationManager对象。

有没有办法确保我的第一个值是准确的? 提前致谢。

- (void)viewDidLoad { [super viewDidLoad]; locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (startingPoint == nil) { NSLog(@"NIL starting point"); self.startingPoint = newLocation; } CLLocationDistance distance = [newLocation distanceFromLocation:startingPoint]; NSString *distanceString = [[NSString alloc] initWithFormat:@"%g m", distance]; distanceLabel.text = distanceString; [distanceString release]; numberOfUpdates++; NSString *countString = [[NSString alloc] initWithFormat:@"%d", numberOfUpdates]; countLabel.text = countString; [countString release]; }

I'm beginning to mess around with the CLLocationManager and I am trying to use the callback method below. I went outside to test it on my iPhone, and with the first few updates, I seem to be getting gibberish values, like all of a sudden my distance is 39meters even though I haven't moved anywhere. Or sometimes it will start at 5, and then jump to 20 meters, again without me moving anywhere. I went outside and walked, and the updates from the initial starting point seemed 'ok,' and then when I walked back, I got back to the original 39 meters starting point. I was wondering if what I am doing below is correct. I also included my viewDidLoad method where I initialize my CLLocationManager object.

Is there a way to ensure that my first values are accurate? Thanks in advance.

- (void)viewDidLoad { [super viewDidLoad]; locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (startingPoint == nil) { NSLog(@"NIL starting point"); self.startingPoint = newLocation; } CLLocationDistance distance = [newLocation distanceFromLocation:startingPoint]; NSString *distanceString = [[NSString alloc] initWithFormat:@"%g m", distance]; distanceLabel.text = distanceString; [distanceString release]; numberOfUpdates++; NSString *countString = [[NSString alloc] initWithFormat:@"%d", numberOfUpdates]; countLabel.text = countString; [countString release]; }

最满意答案

GPS是一项不完善的技术。 大气条件,卫星可用性(和位置),天空能见度,附近物体(建筑物)反射的信号都会导致其固有的不准确性。 尽管甚至有一个“精度”值( 通常相当不错) - 即使这不是完全可靠的。

飞机不允许使用GPS进行精确测量 - 即使他们的接收机不够精确,并且需要其他技术(这有其自身的问题)。

尝试运行标准的“地图”应用程序并将其用作比较。 我认为你的代码很好 - 它只是GPS而已。

当然,我这样说是因为我正在开发自己的海上导航应用程序,自己也遇到过所有这些问题。

GPS is an imperfect technology. Atmospheric conditions, sattelite availability (and position), sky visibility, signals bouncing off nearby objects (buildings) all contribute to it's inherent inaccuracy. Though there is even an "accuracy" value (which is usually pretty good) - even this is not completely reliable.

Airplanes are not allowed to use GPS for precision approaches - even their receivers aren't accurate enough, and they require other technologies (which have their own issues).

Try running the standard "Maps" application and use it as a comparison. I think your code is good - it's jut GPS.

Of course I am saying this because I am working on my own maritime navigation application, an running into all these issues myself.

更多推荐

本文发布于:2023-07-28 06:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1301638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:准确   位置   CLLocationManager   accurate   location

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!