gpt4 book ai didi

ios - swift 将 CLLocation 转换为 CLLocationCoordinate2D

转载 作者:IT王子 更新时间:2023-10-29 05:26:03 26 4
gpt4 key购买 nike

Hi 在理解 swift 编程中的声明部分时遇到了很多麻烦。我有一行代码 CLLocationCoordinate2D myCoordinate = myLocation.coordinate;与我在 Swift 编程中声明的一样,但出现错误

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

fatal error :无法展开 Optional.None

最佳答案

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...")
}

关于ios - swift 将 CLLocation 转换为 CLLocationCoordinate2D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24363911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com