简体   繁体   English

在swift中CLLocation到CLLocationCoordinate2D

[英]CLLocation to CLLocationCoordinate2D in swift

Hi had lot of trouble in understanding the declaration part in swift programming. 你在快速编程中理解声明部分时遇到了很多麻烦。 I have line of code CLLocationCoordinate2D myCoordinate = myLocation.coordinate; 我有一行代码CLLocationCoordinate2D myCoordinate = myLocation.coordinate; As same as I declared in Swift programming but I'm getting error 和我在Swift编程中声明的一样,但是我遇到了错误

var location1:CLLocation! = locationManager1.location
var coordinate1:CLLocationCoordinate2D = location1.coordinate

fatal error: Can't unwrap Optional.None 致命错误:无法打开Optional.None

the location1 can be nil , and you have to check whether or not it is nil before you access to its proprties, like eg this: location1可以是nil ,你必须在访问其属性之前检查它是否为nil ,例如:

let locationManager1: CLLocationManager // your location manager

// ...

if let location1: CLLocation = locationManager1.location {
    var coordinate1: CLLocationCoordinate2D = location1.coordinate

    // ... proceed with the location and coordintes

} else {
    println("no location...")
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM