在应用程序中,我需要计算两点之间的距离。我正在这样做。
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
NSLog(@"updating");
//Getting my concerts
arrConcerten = [matches mutableCopy];
for (Event *concert in arrConcerten) {
CLLocation *restaurnatLoc = [[CLLocation alloc] initWithLatitude:[concert.eve_latitude floatValue] longitude:[concert.eve_longitude floatValue]];
CLLocationDistance meters = [restaurnatLoc distanceFromLocation:newLocation];
NSLog(@"meters are %f",meters);
if(meters > 5000){
[locationManager2 stopUpdatingLocation];
NSString *message2 = [NSString stringWithFormat:@"Long = %f and lat= %f and Concert Lat = %f and long = %f",newLocation.coordinate.longitude,newLocation.coordinate.latitude,[concert.eve_latitude floatValue],[concert.eve_longitude floatValue]];
NSLog(@"%@",message2);
}else{
NSLog(@"too far away");
}
}
}
这就是我的日志所说的。
2013-10-17 15:57:23.518 Domino[7468:907] meters are 7973.753294
2013-10-17 15:57:23.520 Domino[7468:907] Long = 5.621456 and lat= 51.097340 and Concert Lat = 51.038139 and long = 5.557330
2013-10-17 15:57:23.896 Domino[7468:907] meters are 27850.874245
2013-10-17 15:57:23.899 Domino[7468:907] Long = 5.621456 and lat= 51.097340 and Concert Lat = 50.860332 and long = 5.493722
如您所见,这些位置彼此靠近。但它仍然说我们离得太远了。有人可以帮助我吗?