사용자가 이동 한 거리를 계산하는 응용 프로그램을 개발 중입니다. 이렇게하려면 CLLocationManager 클래스를 사용하고 있지만 처음에는 캐시 된 데이터를 가져오고 거리 변수도 갑자기 증가합니다. 제발 도와주세요 ... 다음 코드를 사용했습니다 ....Corelocation의 잘못된 거리
참고 : 거리는 정적 var입니다. 여기
- (void)viewDidLoad {
[super viewDidLoad];
//bestEffortAtLocation = nil;
oldLocat = [[CLLocation alloc]init];
newLocat = [[CLLocation alloc]init];
locationManager =[[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
// test that the horizontal accuracy does not indicate an invalid measurement
if (newLocation.horizontalAccuracy < 0) return;
NSLog(@"accuracy %d",newLocation.horizontalAccuracy);
// test the age of the location measurement to determine if the measurement is cached
// in most cases you will not want to rely on cached measurements
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
//NSLog(@"time %d",locationAge);
if (locationAge > 5.0) return;
self.oldLocat = oldLocation;
self.newLocat = newLocation;
double latDegrees = newLocation.coordinate.latitude;
NSString *lat = [NSString stringWithFormat:@"%1.5f°",latDegrees];
latLabel.text = lat;
double longDegrees = newLocation.coordinate.longitude;
NSString *longt = [NSString stringWithFormat:@"%1.5f°",longDegrees];
longLabel.text = longt;
[self computeDistanceFrom:oldLocat tO:newLocat];
}
-(void)computeDistanceFrom:(CLLocation *)oldL tO:(CLLocation *)newL
{
NSLog(@"oldd %@",oldL);
NSLog(@"new %@",newL);
distance = distance + [oldL getDistanceFrom:newL];
NSLog(@"distance %f",distance);
}
콘솔은 다음 데이터를 표시
.......
정확도 oldd 0 (NULL) 28.62114850 < 새로운 77.37001021가> +/- 80.00m (속도 MPS -1.00/-1.00 코스) 거리 2010-06-22 0,530 19시 21분 59초 @ 0.000000
정확도 oldd < 28.62114850 0 77.37001021> +/- 80.00m (-1.00 속도 MPS/코스 -1.00) @ 2010-06-22 19:21:59 +0530 신규,245,080,543,210 28.61670485, 77.37068155> +/- 80.00m (MPS 속도 -1.00/-1.00 코스) 거리 498.211345
정확도 0 oldd < 28.61670485 19시 22분 0초 2010-06-22 0,530 @ +77.37068155> +/- 80.00m (속도 -1.00 mps/코스 -1.00) @ 2010-06-22 19:22:00 +0530 신규 < +28.62112748, +77.36998540> +/- 80.00m (속도 -1.00 mps/course -1.00) @ 2010-06-22 19:23:02 +0530 distance 994.432508
감사합니다 progrmr하지만 정확히 타임 스탬프를 사용하여 캐시 된 데이터를 제거하는 방법을 말해 줄 수 있습니다 ........ 그리고 거리를 계산하는 위의 접근 방식이 잘못된 경우 어떻게 진행해야합니까 ...... 거기에 있습니다. 거리를 계산하는 다른 방법 ..... coz 나는 거리, 속도 등등을 계산하는 것과 같은 일을하는 앱 스토어에서 많은 앱을 보았습니다. 당신의 소중한 제안을주세요. – Siddharth
오래된 캐시 데이터를 제거하는 방법을 보여주기 위해 코드 샘플을 추가했지만 코드에서 이미 수행하고 있습니다. – progrmr