Swift:如何使用 CLLocationCoordinate2D 将坐标存储为字符串或整数?

Swift: How can I store coordinates using CLLocationCoordinate2D as a string or an int?

到目前为止,这是我的代码。我正在尝试将 locValue.latitude 和 locValue.longitude 的值存储为字符串或整数。我尝试在方法中定义 return 类型(-> 字符串等),但我收到一条错误消息,指出 didChangeAuthorizationStatus 方法与协议 CLLocationManagerDelegate 中的可选要求方法 locationManager 冲突。

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if status == .AuthorizedAlways {
        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
        self.dispLocation.text = "locations = \(locValue.latitude) \(locValue.longitude)"
    }
}

只需声明两个字符串

var lat  = ""
var long = ""

然后从您的位置解析 latlong

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let location:CLLocationCoordinate2D = manager.location!.coordinate
    lat = String(location.latitude)
    long = String(location.longitude)
}

你也可以试试这个-

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    var locValue:CLLocationCoordinate2D = CLLocationCoordinate2DMake(0, 0);

    if manager.location?.coordinate != nil {
        locValue = (manager.location?.coordinate)!
    }

    let locations = "locations = \(locValue.latitude) \(locValue.longitude)"
    print(locations)
}