Iphone CLLocationManager奇怪的问题
我有一个MKMapView,每次加载视图或调用Iphone CLLocationManager奇怪的问题,iphone,ios,cllocationmanager,Iphone,Ios,Cllocationmanager,我有一个MKMapView,每次加载视图或调用showLocation自定义类方法时,我都会删除注释 我需要精确到最好 -(void)viewDidLoad { locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.distanceFilter = kCLDistanceFilterNone; locationMan
showLocation
自定义类方法时,我都会删除注释
我需要精确到最好
-(void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
}
-(IBAction) showLocation:(id) sender{
[locationManager startUpdatingLocation];
}
- (void) locationManager:(CLLocationManager *) manager
didUpdateToLocation:(CLLocation *) newLocation
fromLocation:(CLLocation *) oldLocation {
// start geocoding with newLocation coordinate which will automatically set annotation.
SVGeocoder *geocodeRequest = [[SVGeocoder alloc]
initWithCoordinate:CLLocationCoordinate2DMake(newLocation.coordinate.latitude, newLocation.coordinate.longitude)];
[geocodeRequest setDelegate:self];
[geocodeRequest startAsynchronous];
[geocodeRequest release];
[locationManager stopUpdatingLocation];
}
我的问题是何时调用didUpdateToLocation
方法?仅在我执行[locationManager startUpdatingLocation]
时找到新位置之后
当用户在旅行和静止时,我面临一些奇怪的问题。
假设用户从A->B->C->D点出发,各点之间间隔1分钟。当我在C点调用我的方法时,它有时返回A点的坐标,有时返回B点,有时返回C点。它只是随机的
当我静止不动的时候就更奇怪了。当我调用showLocation
方法时,我会得到不同的坐标,即使我已经连接了我家的WiFi
我正在考虑实施DidUpdateLocation,以便在5秒内获得最佳效果。如果在5秒内,它找到了我定义的精度的特定位置,则使用坐标。如果没有,请使用在5秒时间范围内找到的最佳值。但由于我是新手,我不知道如何编写这样的代码。我读了NSTimer,它似乎可以工作
有什么建议吗
提前多谢 删除[locationManager停止更新位置];从您的代码,然后尝试 您从点A接收位置的原因之一是CoreLocation返回它首先拥有的最后一个有效位置,直到它能够获得更准确的位置。当您调用
[locationManager startUpdatingLocation]
它将反复返回-didUpdateToLocation
,直到您完成统计,最后调用-stopUpdateLocation
我认为在你停止更新你的位置之前,你只需要给它一点时间来获得更好的位置修正。我会考虑将停止更新位置从您的代码> -DIdUpDestoToLoope<代码>移动到一个不同的方法。