gpt4 book ai didi

ios - 在 Swift 中将 CLLocation 转换为 MKMapItem

转载 作者:行者123 更新时间:2023-11-28 05:51:07 26 4
gpt4 key购买 nike

我从 Core Location 的 locationManager 中检索到用户位置的 CLLocation。为了计算到 map 项的距离,我想将 CLLocation 转换为 MKMapItem

我想你可以获取 CLLocation 的坐标,从中创建一个 MKPlacemark,最后从 中创建一个 MKMapItem MKPlacemark 执行如下操作:

let currentLocation:CLLocation = locationManager.location
var coord : CLLocationCoordinate2D = currentLocation.coordinate
let myPlacemark = MKPlacemark(coordinate: coord)
let myMapItem = MKMapItem(placemark: myPlacemark)

对于这项任务来说,这似乎相当冗长,我想知道是否没有更直接的方法来做到这一点?

提前感谢您的任何建议。

最佳答案

因为它是您要为其创建 MKMapItem 的用户当前位置,您可以这样做:

let myMapItem = MKMapItem.mapItemForCurrentLocation()

这也省去了获取用户位置的麻烦! :)

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

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