title: How to compare user'r current location to other locations and display them in UITable View?
body: <p>I am developing an app in swift and I have to compare user's current location to the other locations taken from a JSON file. Then I have to display all of the locations which are in a certain range from the user's location. This range I take from a UISlider. I mean when the user selects 25km in the slider, the app has to determine the current user's location and display all of the fruits which are in this range.</p>
  
  <pre><code>   import UIKit
     import SwiftyJSON
     import MapKit
     import CoreLocation
  
  
   class TableViewController: UITableViewController,CLLocationManagerDelegate {
   @IBOutlet weak var Bar: UIToolbar!
  
  
  @IBOutlet weak var LabelTest: UILabel! // this is the slider value, I segue it from the previous viewcontroller
  var manager = CLLocationManager()
  
  struct Fruit {
      let name : String
      let location : CLLocation
      let imageURL : NSURL
      let description : String
  }
  var fruits = [Fruit]()
  
  
  func parseFruits() {
      guard let url = NSBundle.mainBundle().URLForResource("cities", withExtension: "json"), jsonData = NSData(contentsOfURL: url) else {
          print("Error finding JSON File")
          return
      }
  
      let jsonObject = JSON(data: jsonData)
  
      let fruitArray = jsonObject["fruits"].arrayValue
      for aFruit in fruitArray {
         let name = aFruit["Name"].stringValue
          let latitude = city["Latitude"] as! Double
          let longitude = city["Longitude"] as! Double
          let location = CLLocation(latitude: latitude, longitude: longitude)
         let imageURL = aFruit["Picture"].stringValue
      let description = aFruit["Description"].stringValue
  
          let fruit = Fruit(name: name,location: location,imageURL: NSURL(string:imageURL)!, description: description )
          fruits.append(fruit)
      }
  
      self.tableView.reloadData()
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
      parseFruits()
  
      // Uncomment the following line to preserve selection between presentations
      // self.clearsSelectionOnViewWillAppear = false
  
      // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
      // self.navigationItem.rightBarButtonItem = self.editButtonItem()
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  // MARK: - Table view data source
  
  override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      // #warning Incomplete implementation, return the number of sections
      return 1
  }
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return fruits.count
      }
  
  
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
       let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as!  TableViewCell
       let fruit = fruits[indexPath.row]
      cell.CellTitle.text = fruit.name
      cell.CellDescription.text = fruit.description
  
  
      let image = UIImage(data: NSData(contentsOfURL:(string: fruit.imageURL))!)
      cell.CellImage.image = image
  
      return cell
            }
  </code></pre>
  
  <p>Currently I am not calculating the user's current location and I am not comparing it, I would be glad if someone can show me how to do that.</p>
  
  <p>edited:</p>
  
  <pre><code>   func CalculateDistance() {
      let userLocation = CLLocation(latitude: lat, longitude: long)
      let destinationLocation = CLLocation(latitude:latitude, longitude: longitude)// latitude and longitude from the json file
      let distance = userLocation.distanceFromLocation(destinationLocation)
  }
  </code></pre>