ios – 将CLLocationCoordinate2D放入Swift的CLLocation

前端之家收集整理的这篇文章主要介绍了ios – 将CLLocationCoordinate2D放入Swift的CLLocation前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个我想要调用方法,当我回到地图的中心,它是在CLLocationCoordinate2D类型.

如何将CLLocationCoordinate2D的结果放入CLLocation?

解决方法

弄清楚了.

当mapView更改区域时,从CLLocationCoordinate2D获取Lat和Lon,并创建一个带有lat和lon的CLLocation变量.

func mapView(mapView: MKMapView!,regionDidChangeAnimated animated: Bool){

    var centre = mapView.centerCoordinate as CLLocationCoordinate2D

    var getLat: CLLocationDegrees = centre.latitude
    var getLon: CLLocationDegrees = centre.longitude


    var getMovedMapCenter: CLLocation =  CLLocation(latitude: getLat,longitude: getLon)

    self.lastLocation = getMovedMapCenter
    self.fetchCafesAroundLocation(getMovedMapCenter)

}

猜你在找的iOS相关文章