這比代碼的理論問題: 我做了至今:憋屈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;
}
感謝你清除我的疑問。 – Shubhank 2012-01-05 10:16:56