当前位置: 动力学知识库 > 问答 > 编程问答 >

ios4 - iPhone CoreLocation - accuracy not working correctly?

问题描述:

I am developing an app which uses gps. i need a high accuracy so i used kCLLocationAccuracyBestForNavigation for the desiredAccuracy.

when i am running the app, the follwing method gets called as expected.

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

within this method i am checking if the accuracy is good enough with the follwing code segment:

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

...

}

but this if-block never gets active, as the newLocation.horizontalAccuracy is not going below 17.00 meters. When i was running this code on iPhone 3GS OS 3.1.2 everything was running fine. but since i upgraded to 4.0.1 it seems that there is a problem with the accuracy. It even doesn't work with kCLLocationAccuracyNearestTenMeters which was also running smooth and stable on iOs 3.1.2.

do you have any hints for me whats going on and how i can solve my problem ?

网友答案:

The problem with your if block is that you are comparing horizontalAccuracy, which is reported in meters, against desiredAccuracy, which is set as the constant value kCLLocationAccuracyBestForNavigation. These constants aren't defined in the documentation, but other constants are just enumerated. So kCLLocationAccuracyBestForNavigation may just be literally equal to 0. Your horizontalAccuracy would never be less than or equal to zero.

You need to test your horizontal accuracy against a an actual number. The best horizontal Accuracy I've gotten is 5.0. So, you may want to change your if statement to !(newLocation.horizontalAccuracy > 5.0).

网友答案:

I need to correct my last anser. kCLLocationAccuracyHundredMeters actually resolves to 100. The same goes for kilometer (1000) and threkilometers (3000). So, you could use those for the comparison. However, kCLLocationAccuracyBest is -1 and BestForNavigation is -2. So, you couldn't compare your horizontalAccuracy with those.

分享给朋友:
您可能感兴趣的文章:
随机阅读: