Ios 在Swift中将CLLocation转换为MKMapItem
我从Core location的locationManager中检索到一个用户位置的Ios 在Swift中将CLLocation转换为MKMapItem,ios,swift,mapkit,core-location,Ios,Swift,Mapkit,Core Location,我从Core location的locationManager中检索到一个用户位置的CLLocation。为了计算到地图项目的距离,我想将CLLocation转换为MKMapItem 我想您可以获得CLLocation的坐标,从中生成MKPlacemark,最后从MKPlacemark生成MKMapItem,执行以下操作: let currentLocation:CLLocation = locationManager.location var coord : CLLocationCoordin
CLLocation
。为了计算到地图项目的距离,我想将CLLocation
转换为MKMapItem
我想您可以获得CLLocation
的坐标,从中生成MKPlacemark
,最后从MKPlacemark
生成MKMapItem
,执行以下操作:
let currentLocation:CLLocation = locationManager.location
var coord : CLLocationCoordinate2D = currentLocation.coordinate
let myPlacemark = MKPlacemark(coordinate: coord)
let myMapItem = MKMapItem(placemark: myPlacemark)
对于这项任务来说,这似乎相当长,我想知道,是否有更直接的方法来完成这项任务
提前感谢您的建议。由于您正在尝试创建mkmaItem的位置是用户的当前位置,因此您可以执行以下操作:
let myMapItem = MKMapItem.mapItemForCurrentLocation()
这也省去了获取用户位置的麻烦!:) 我需要你