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
func closestLoc(userLocation:CLLocation){
var distances = [CLLocationDistance]()
for location in locations{
let coord = CLLocation(latitude: location.latitude!, longitude: location.longitude!)
distances.append(coord.distance(from: userLocation))
print("distance = \(coord.distance(from: userLocation))")
}
let closest = distances.min()//shortest distance
let position = distances.index(of: closest!)//index of shortest distance
print("closest = \(closest!), index = \(position)")
}