title: iOS - The best way to measure distance
body: <p>I'm currently working on a project where I need the user to tell where (on the real world map) to build a wall.</p>
  
  <p><strong>Question</strong>: What (in your opinion) is the most accurate way for the user to show(/tell) where to place the wall?</p>
  
  <p><em>Idea 1</em> I have thought about drawing on a map, But that wouldn't be so accurate.</p>
  
  <p><em>Idea 2</em> Another thing that I have thought of is, that the user should place their phone on the beginning and the end of the wall. And in that way the app could use <code>CLLocationManager</code> to print the locations on the map, and also measure the distance between the two ends. </p>
  
  <p>This is the code that I tried my thought with, but it wasn't really that accurate at all.</p>
  
  <pre><code>let locationManager = CLLocationManager()
  
  var location1: CLLocation = CLLocation()
  var location2: CLLocation = CLLocation()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      setup()
  }
  
  func setup() {
          resett.isHidden = true
  
          // Ask for Authorisation from the User.
          self.locationManager.requestAlwaysAuthorization()
  
          // For use in foreground
          self.locationManager.requestWhenInUseAuthorization()
  
          if CLLocationManager.locationServicesEnabled() {
              locationManager.delegate = self
              locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
              locationManager.activityType = .fitness
              locationManager.startUpdatingLocation()
          }
      }
  
      func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
          let locValue:CLLocationCoordinate2D = manager.location!.coordinate
          currentCord.text = "\(locValue.latitude) \(locValue.longitude)"
      }
  
      func measure(cord1: CLLocation, cord2: CLLocation) -&gt; Float {
          let distanceInMeters = cord1.distance(from: cord2) //result is in meters
          return Float(distanceInMeters)
      }
  
      func calculateCoordinates(status: Int) {
          let coordinate = calculate()
  
          if status == 1 {
              location2 = coordinate
  
              let measured = measure(cord1: location1, cord2: location2)
              print("\(measured) m")
              displayLabel.text = "\(measured)m"
              resett.isHidden = false
          } else {
              location1 = coordinate
          }
      }
  
      func calculate() -&gt; CLLocation {
          let locValue:CLLocationCoordinate2D = locationManager.location!.coordinate
          let coordinate = CLLocation(latitude: locValue.latitude, longitude: locValue.longitude)
  
          return coordinate
      }
  
      @IBAction func FirstAction(_ sender: Any) {
          button1.setTitle("Klar", for: .normal)
          calculateCoordinates(status: 0)
      }
  
      @IBAction func SecondAction(_ sender: Any) {
          button2.setTitle("Klar", for: .normal)
          calculateCoordinates(status: 1)
      }
  </code></pre>
  
  <p><strong>Thanks in advance!</strong></p>