如何从(userLocation.swift)中的一个类(GPSLocation)获取定位结果,并在文件(target.swift)中的另一个类中使用它们?
我需要以下国家/地区的国家/地区代码,城市,经度和纬度:
userLocation.swift
import UIKit
import MapKit
class GPSLocation {
func getGPSLocation(completion: () -> Void) {
let locManager = CLLocationManager()
var currentLocation: CLLocation!
locManager.desiredAccuracy = kCLLocationAccuracyBest
if (CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways) {
currentLocation = locManager.location
let latitude = String(format: "%.7f", currentLocation.coordinate.latitude)
let longitude = String(format: "%.7f", currentLocation.coordinate.longitude)
let location = CLLocation(latitude: currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude)
fetchCountryAndCity(location: location) { countryCode, city in
// debugPrint("Country:", countryCode)
// debugPrint("City:", city)
}
// debugPrint("Latitude:", latitude)
// debugPrint("Longitude:", longitude)
}
}
//MARK: Find …Run Code Online (Sandbox Code Playgroud)