5

到目前为止,这是我拥有的代码。我正在尝试将 locValue.latitude 和 locValue.longitude 的值存储为字符串或整数。我已经尝试在方法中定义返回类型(-> String 等),但我收到一条错误消息,指出 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)"
    }
}
4

2 回答 2

8

只需声明两个字符串

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)
}
于 2016-03-21T22:25:40.723 回答
3

你也可以试试这个 -

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)
}
于 2016-03-21T22:50:07.133 回答