title: How to use user location out of locationmanager function swift 3
body: <p>i am kinda new to coding and have come up with this problem. I im making af trashcanfinder app based on MapKit and I would like to show the distance from the user location to my pins on the map. I have already made my function to convert a CLLocationCoordinate2D to a CLLocation, and have a function to show distance from one point to another, but I can't seem to use the user location out of the locationmanager function. </p>
  
  <p>This is my code:</p>
  
  <pre><code> @IBOutlet weak var mapView: MKMapView!
  
  let manager = CLLocationManager()
  
  
  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  
      let location = locations[0]
      let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
      let myLocation = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
      let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
  
      mapView.setRegion(region, animated: true)
  
      self.mapView.showsUserLocation = true
  
  
  }
  
  
  
      func distancePointToPoint(location1: CLLocationCoordinate2D, location2: CLLocationCoordinate2D) -&gt; String {
          let cllocation1 = converter(location: location1)
          let cllocation2 = converter(location: location2)
          let distance = cllocation1.distance(from: cllocation2)
          let shortDistance = distance - distance.truncatingRemainder(dividingBy: 0.1)                                   //makes sure there is only one number behind comma
          if shortDistance &lt; 0 {
              return "The distance is \(shortDistance) meters"
          }
          else {
              return "The distance is \(shortDistance - (shortDistance / 1000).truncatingRemainder(dividingBy: 0.1)) kilometers"
          }
      }
  </code></pre>
  
  <p>So I need to use the user location as location1 in the distancePointToPoint function. </p>
  
  <p>I know that with any other function I could just return the value, but I don't have any values to give the locationmanager function as it will get it from the device itself. </p>
  
  <p>I already have done research and the only other way I have found is to put myLocation variable outside of the function and only change the value inside the function, but the xcode starts to complain that the class doesn't have an initializer and I don't know what to do.</p>
  
  <p>Sorry if I made any stupid mistakes as I have just started to learn code.</p>
  
  <p>Any help is appreciated!</p>