Smallest array from current location iOS Swift



The below function was used to return the smallest distance location arrays from Location you sent.
Also, the mutable array must have a model with lat, lang and distance values.
Code:
    func matchLocation(currentLocation:CLLocation,geoPlace:NSMutableArray) ->NSMutableArray {

        
        var smallestDistanceArray = NSMutableArray()
        
        for location in geoPlace {
            let tempLocation = location
            let markLocation:CLLocation = CLLocation(latitude: tempLocation.latitude, longitude: tempLocation.longitide)
            let distance = markLocation.distance(from: currentLocation)

            if  distance < Double(tempLocation.distance) {
                smallestDistanceArray.add(tempLocation)
            }
        }
        return smallestDistanceArray
    }

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift