如何等到位置完全找到? (核心位置) [英] How to wait until location is completely found? (Core Location)

查看:153
本文介绍了如何等到位置完全找到? (核心位置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程式有问题。我试图找到用户的位置以最好的精确度,以确定他们的邮政编码。目前我有一个按钮,当按下时,启动一个名为 locateMe 的方法。

   - (IBAction)locateMe; {
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];然后我已经实现了 didUpdateToLocation: / p>

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

NSLog(@找到位置!%f,%f,newLocation.coordinate.latitude,newLocation.coordinate.longitude);
}

我以前在 didUpdateToLocation 但是当我测试一些东西,我意识到,第一个位置,它发现是不精确的。所以,我把 NSLog 调用在那里,它给了我一个类似下面的输出...

 找到位置! 39.594093,-98.614834 
找到的位置! 39.601372,-98.592171
找到位置! 39.601372,-98.592171
找到位置! 39.611444,-98.538196
找到的位置! 39.611444,-98.538196

如你所见,它首先给出一个不正确的值在我的应用程序中导致问题,因为它没有给出正确的位置。



所以,这里是我的问题。有任何方法我可以等待位置管理器完成找到最精确的位置吗?



提前感谢!



编辑:我想要这样的:

  if(newLocation.horizo​​ntalAccuracy< ; = locationManager.desiredAccuracy){
}

但它永远不会被调用!

解决方案

核心位置经常调用didUpdateToLocation检测到位置检测到上一个会话。所以你可以跳过它发送给你的第一个位置。如果你要根据这些数据计算用户的速度,你应该知道这种行为。在这种情况下,行人通常在100英里/小时。 :)



如果您使用地理坐标提交评论或照片,则在用户输入评论屏幕时开始接收地理坐标。而他将键入一条消息 - 检测到的位置变得相当准确。


I have a problem within my app. I'm trying to find the user's location to the best preciseness in order to determine their zip-code. Currently I have a button that, when pressed, starts a method named locateMe.

-(IBAction)locateMe; {
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

Then I've implemented didUpdateToLocation:

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

       NSLog(@"Found location! %f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude);
 }

I had previously done much more complicated stuff in didUpdateToLocation but as I tested some things I realized that the first location it found was not precise in the least. So, I put the NSLog call in there and it gave me an output similar to below...

Found location! 39.594093,-98.614834
Found location! 39.601372,-98.592171
Found location! 39.601372,-98.592171
Found location! 39.611444,-98.538196
Found location! 39.611444,-98.538196

As you can see, it first gives me a value which is not correct, which was causing problems within my app because it wasn't giving the correct location.

So, here's my question. Is there any way I can wait for the location manager to finish finding the most precise location?

Thanks in advance!

EDIT: I'm wanting something like this:

if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
}

But it never gets called!

解决方案

Core Location often call didUpdateToLocation with location detected durning previous session. So you can just skip first location that it send to you. And if you're calculating user speed based on this data you should to be aware of that behavior. Pedestrians at 100mph is usual in that case. :)

If you're submitting comments or photos with geo coordinates - start receiving geo coordinates when user did enter to write a comment screen. while he will type a message - detected location become pretty accurate.

这篇关于如何等到位置完全找到? (核心位置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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