gpt4 book ai didi

ios - 如何在 Swift 中提取纬度/经度 placemark.coordinate?

转载 作者:行者123 更新时间:2023-11-28 12:31:20 25 4
gpt4 key购买 nike

我在我的应用程序中添加了位置搜索栏。 tableview Controller 由用户位置纬度/经度以及目的地(地址用户输入到搜索栏中)组成。据我所知,纬度/经度在 placemark.coordinate 内:

placemark.coordinate = CLLocationCoordinate2D(latitude: 45.253519203737767, longitude: -66.070974382763978)

我有两个变量:destLatdestLong。如何从 placemark.coordinate 中提取纬度和经度并将其放入上述两个变量中?

相关代码:

// cache the pin
selectedPin = placemark

// clear existing pins
mapView.removeAnnotations(mapView.annotations)
let annotation = MKPointAnnotation()
annotation.coordinate = placemark.coordinate
annotation.title = placemark.name
if let city = placemark.locality,
let prov = placemark.administrativeArea {
annotation.subtitle = "\(city), \(prov)"
}

let destination = placemark.coordinate
print("Destination coordinates: \(destination)")
let name = placemark.name
print("Placemark Name: \(name!)")


mapView.addAnnotation(annotation)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(placemark.coordinate, span)
mapView.setRegion(region, animated: true)

控制台输出:

enter image description here

最佳答案

也许你想多了。您可以像任何其他变量一样为这些变量赋值:

let (destLat, destLong) = (placemark.coordinate.latitude, placemark.coordinate.longitude)

关于ios - 如何在 Swift 中提取纬度/经度 placemark.coordinate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42043145/

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