2010-08-02 107 views
0

我需要檢測iphone的小位置變化,我嘗試了稱爲定位我的樣本,但它不能識別位置的小變化。有沒有辦法做到這一點?小位置變化檢測

在此先感謝。

問候 約翰

+0

GPS準確度並不那麼精確 - 您可以使用加速度傳感器嗎? – Justin 2010-08-02 13:15:21

+0

你想要多少準確度?當定位精度設置爲最佳時,GPS在定位用戶方面做得很好。 – 2010-08-02 13:33:03

+0

@Justin,我如何使用加速度計來確定距離? – 2010-08-03 07:41:32

回答

0

是多麼小的變化,你期望?

也許你應該將精度設置爲最大值並計算委託方法的位移。

配置位置管理器給你它是最好的。


    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
    [locationManager setDistanceFilter:0.0]; 

,然後委託方法:


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    // Calculate the distance between the two locations 
    CGFloat distance = [newLocation distanceFromLocation:oldLocation]; 

    if (distance >= MIN_DISPLACEMENT) { 
     // Do something 
    } else { 
     // Do something 
    } 
} 

從位置管理器獲得更準確的數據,設置適當的鍵上的Info.plist UIRequiredDeviceCapabilities(位置服務,GPS)。

+0

我試過這個解決方案,但我需要實時更新距離,GPS需要時間來獲取距離,這是不適合我的應用程序。 – 2010-08-22 16:22:17

+0

@John,如果您需要實時更新,您需要利用加速度計或(在iOS4上)http://developer.apple.com/iphone/library/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MotionEvents/MotionEvents。 HTML#// apple_ref/DOC/UID/TP40009541-CH4-SW26 – vfn 2010-08-23 03:28:32