我从服务器接收到多个餐厅的纬度/经度。我想要计算每个餐厅与用户当前的纬度/经度之间的距离。
我从服务器接收到多个餐厅的纬度/经度。我想要计算每个餐厅与用户当前的纬度/经度之间的距离。
CLLocation *currentLoc = /* Assume you have found it */;
CLLocation *restaurantLoc = [[CLLocation alloc] initWithLatitude:restaurantLat longitude:restaurantLng];
CLLocationDistance meters = [restaurantLoc distanceFromLocation:currentLoc];
// Go ahead with this
func calculateDistanceFromUser(location:CLLocation)->CLLocation!{
if let userLocation = self.userUpdatedLocation{ //CLLocation
let meters = location.distance(from: userLocation)
return meters
}
return nil
}