I want to be able to use the latitude string outside of the function getLatitude. I have tried to just enter "return latstring" but this didn't work because it is like one layer deeper??? However I have no clue how to fix this. Here is the code:
private func getLatitude() -> String {
let address = "Oslo"
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString(address) { (placemarks, error) in
guard
let placemarks = placemarks,
let location = placemarks.first?.location
else { return }
// do whatever you want with CLLocation object
let latitude = location.coordinate.latitude
let latstring = String(latitude)
return(latstring)
// CLLocationCoordinate2D(latitude: 40.7129822, longitude: -74.007205)
}
}