Adding Coordinates into an array from CLLocationManager with Swift 3.0 in Xcode 8 : Ive asked this question previously, however I was not very clear!
I am trying to create an array containing only recent location coordinates, which does not span over a certain distance (2000 metres).

The array needs to have certain conditions: 

 1. Not to have any repeated coordinates next to each other within the array i.e the array must not append new coordinates while the user is stopped.
 2. The span must be the sum of distances between each coordinate, in the order they are entered into the array. It can not be the single span between the oldest coordinate and the newest coordinate.
 3. The old coordinates must be deleted, once the sum of distances exceeds the certain distance (2000 metres).

This means the array count will be changing depending on the users average speed, new coordinates will be added constantly and old coordinates deleted conditionally.

I have no idea where to start in building this array, so any input would be greatly appreciated.




Heres my code calling the location coordinates:


     import UIKit
     import MapKit
     import CoreLocation


     class View3: UIViewController , CLLocationManagerDelegate{
    

    
   
    @IBOutlet weak var map: MKMapView!
    

    let manager = CLLocationManager()
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations[0]
        let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01,0.01) //shows the size of map screen
        let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude,location.coordinate.longitude)
        let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
        map.setRegion(region, animated: true)
        self.map.showsUserLocation = true
 
 
    override func viewDidLoad() {
        super.viewDidLoad()
     manager.delegate = self
        manager.desiredAccuracy = kCLLocationAccuracyBest
        manager.requestWhenInUseAuthorization()
        manager.startUpdatingLocation()
        
        self.map.isZoomEnabled = false
        self.map.isScrollEnabled = false
        self.map.isUserInteractionEnabled = false  
      }
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }