要查找获取的数据中最近的位置,您需要计算从当前位置到每个位置的距离。然后,只需对这些数据进行排序,就可以从现有的坐标mapkit中获取最近的位置。
以下是找出距离的方法...
-(float)kilometresBetweenPlace1:(CLLocationCoordinate2D) currentLocation andPlace2:(CLLocationCoordinate2D) place2
{
CLLocation *userLoc = [[CLLocation alloc] initWithLatitude:currentLocation.latitude longitude:currentLocation.longitude];
CLLocation *poiLoc = [[CLLocation alloc] initWithLatitude:place2.latitude longitude:place2.longitude];
CLLocationDistance dist = [userLoc getDistanceFrom:poiLoc]/(1000*distance);
NSString *strDistance = [NSString stringWithFormat:@"%.2f", dist];
NSLog(@"%@",strDistance);
return [strDistance floatValue];
}