2012-01-05 48 views
1

這比代碼的理論問題: 我做了至今:憋屈CLLocation

我的應用在很大程度上依賴於位置跟蹤。

我在5個小時前發佈了一個關於它的問題,但沒有一個合適的答案,現在很老了,在那裏提出一個新問題.i我會在得到這個問題的答案後關閉它。

我想要做的是有一個按鈕,用戶press.it讓位置管理器開始更新位置,然後移動每5英尺。我想讓iPhone播放隨機聲音。 我實施了正確的代碼給下面,現在我在我的設備上測試從一個地方移動到這裏在我家。通過試驗和錯誤我知道,前幾個地點是iPhone試圖獲得準確的結果,一般都要避免,所以我把它作爲一個條件來處理超過2秒之前的地點。

現在我的真實問題: 我有我的設備上的無線網絡(沒有GPS和不能),所以經過幾次初始無用的位置更新。我的警報停止顯示..我就像:爲什麼不工作。我把它設置爲最準確的。過濾到1.5米..我在房子裏移動了15英尺,沒有更新?現在我認爲這是因爲它通過無線網絡獲取位置,因此它沒有創建新的位置,即使我移動了40個左右的位置無線上網。?我對麼?

如果這是真的..任何人都可以告訴這將在gps ..正確工作..美國用戶..他們有很多塔..以便我的應用程序將正確更新新的位置是至少5米遠從先前的位置..

很抱歉的長期問題。有我太多的疑惑..

-(id) init 
{ 
    if(self = [super init]) 
     { 
      locationManager = [[CLLocationManager alloc] init]; 
      locationManager.delegate = self; 
//   locationManager.distanceFilter = 1.5; 
      locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
      return self; 
     } 
    return nil; 
} 



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


    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New Lcoation" 
                message:nil 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 


    self.currentLocation = newLocation; 

    BOOL newLocationIsValid = [self isValidLocation:newLocation withOldLocation:oldLocation]; 
    if(newLocationIsValid && oldLocation) 
    { 
     int distance = [newLocation distanceFromLocation:oldLocation]; 
     if(distance >2 && distance <10) 
     { 

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Distance" 
                 message:[NSString stringWithFormat:@"%i meters",distance] 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
      [fileURl release]; 
     } 
    } 
} 

-(BOOL)isValidLocation:(CLLocation*)newLocation withOldLocation:(CLLocation*)oldLocation 
{ 

    if(newLocation.horizontalAccuracy < 0) 
    { 
     return NO; 
    } 
    NSTimeInterval secondsSinceLastPoint = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp]; 
    if(secondsSinceLastPoint < 0) 
    { 
     return NO; 
    } 

    if(secondsSinceLastPoint < 2) 
    { 
     int distance = [newLocation distanceFromLocation:oldLocation]; 

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Distance" 
                 message:[NSString stringWithFormat:@"%i meters",distance] 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
     return NO; 
    } 

    return YES; 
} 

回答

2

是的,不工作,因爲你使用wifi進行定位。位置服務只是知道你的wifi是在哪裏,而不是你的位置相對於你的WiFi(這將是很好的)。

所以爲了您的服務,您必須使用gps。即使如此,準確性並不保證。

看到http://www.kowoma.de/en/gps/accuracy.htm

+0

感謝你清除我的疑問。 – Shubhank 2012-01-05 10:16:56

1

當你不使用真實的GPS信號的位置通過三角測量,其檢索絕對不會達到你想要的準確度。即使有很多WiFi或手機信號塔,其準確度仍然是幾米,更像是100,然後是10.

您想要的精度只能用GPS實現,有些情況下精度只能達到100米左右。這一切都取決於GPS信號質量。

+0

感謝你清除我的doubt..only如果我可以接受這兩個正確答案:d \ – Shubhank 2012-01-05 10:17:21