In the question posted here, the user asked:
I have an array full of longitudes and latitudes. I have two double variables with my users location. I\'d like
For Swift 3 I have created this little piece of "functional" code:
let coord1 = CLLocation(latitude: 52.12345, longitude: 13.54321)
let coord2 = CLLocation(latitude: 52.45678, longitude: 13.98765)
let coord3 = CLLocation(latitude: 53.45678, longitude: 13.54455)
let coordinates = [coord1, coord2, coord3]
let userLocation = CLLocation(latitude: 52.23678, longitude: 13.55555)
let closest = coordinates.min(by:
{ $0.distance(from: userLocation) < $1.distance(from: userLocation) })