title: How to use Longitude and Latitude values from locationManager function elsewhere in my app in Swift
body: <p>I am using the <code>CoreLocation</code> framework to get the user's location when they open up my app. I use this function:</p>
  
  <pre><code>func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
      var locValue:CLLocationCoordinate2D = manager.location!.coordinate
  
  
      print("locations = \(locValue.latitude) \(locValue.longitude)")
  
  }
  </code></pre>
  
  <p>to get the user's longitude and latitude position, and I can see them by printing them to the logs. This works fine. </p>
  
  <p>elsewhere in my app (but in the same <code>viewController.swift</code> file) I have code that uses the OpenWeatherMap API, and I have a string that contains the url for this, which return JSON. </p>
  
  <p>In my <code>viewDidLoad</code>, I use:</p>
  
  <pre><code>getWeatherData("http://api.openweathermap.org/data/2.5/weather?lat=XXXXXX&amp;lon=XXXXXX&amp;appid=(MY-APP-ID)")
  </code></pre>
  
  <p>I need to place the Long and Lat values that I've acquired in the <code>locationManager</code> function, into this string, which I know I can do by <code>"\()"</code> within the url string.</p>
  
  <p>My problem is, I can currently only use these values inside the <code>locationManager</code> function. How can I store them in a value outside of this function, so I can add them into my URL string?</p>
  
  <p>Thanks</p>