我正在使用CLLocationManger更新當前位置。儘管它給我的位置,但我所得到的位置是更老的時間戳。我面臨的問題是,如何強制locationcontroller更新新的位置而不是緩存的位置。CLLocationManger給出了舊的位置。如何獲得新的位置?
目前我使用本教程......
http://www.mobileorchard.com/hello-there-a-corelocation-tutorial/
有人知道如何在當前的時間戳沒有緩存的一個更新的位置?
我正在使用CLLocationManger更新當前位置。儘管它給我的位置,但我所得到的位置是更老的時間戳。我面臨的問題是,如何強制locationcontroller更新新的位置而不是緩存的位置。CLLocationManger給出了舊的位置。如何獲得新的位置?
目前我使用本教程......
http://www.mobileorchard.com/hello-there-a-corelocation-tutorial/
有人知道如何在當前的時間戳沒有緩存的一個更新的位置?
你是在模擬器上還是在iPhone上運行你的項目?如果您正在模擬器上運行項目,則
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
將只被調用一次。
如果您正在設備上進行測試,則應在每次更改您的位置時調用它。
確保您已設置的位置管理器屬性,
locationManager.delegate=self;
[locationManager startUpdatingLocation];
希望幫助...
您可以使用進行選擇使用此方法
- (IBAction)update {
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];
NSLog(@"*********this is location update method of login view controller");
[locmanager startUpdatingLocation];
}
-(void)awakeFromNib {
[self update];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if (wasFound) return;
wasFound = YES;
CLLocationCoordinate2D loc = [newLocation coordinate];
lat2 = [[NSString stringWithFormat: @"%f", loc.latitude]retain];
logg2= [[NSString stringWithFormat: @"%f", loc.longitude]retain];
NSLog(@"latitude is %@",lat2);
NSLog(@"longitude is %@",logg2);
}
調用Update方法在viewdidload方法中。這裏lat2和logg2是字符串值。 如果問題無法解決,然後鍵入如何找到google.you目前的位置將得到很多的例子與解釋的源代碼
你可以做的最好的是扔掉太舊的地點,無論你決定的任何標準爲您的應用程序設置。重新啓動位置管理器應該告訴系統你想要一個新的位置,但是通常你找回的第一個位置可能是上一次的位置。檢查時間戳可能是你所能做的,但要準備好可能永遠不會得到更新的位置。根據我的經驗,我發現如果設備沒有移動,如果它檢測到當前位置足夠好,就不會用新位置更新系統。