把CLLocationCoordinate2D放到Swift的CLLocation中

Chr*_*ley 18 mapkit cllocation ios cllocationcoordinate2d swift

我有一个我想要调用的方法但是当我回到地图的中心时,它处于CLLocationCoordinate2D类型.

如何将CLLocationCoordinate2D的结果放入CLLocation?

Chr*_*ley 36

弄清楚了.

当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)

}
Run Code Online (Sandbox Code Playgroud)