将CLLocationCoordinate2D放入Swift中的CLLocation。

22

我有一个想要调用的方法,但是当我获取地图中心时,它以"CLLocationCoordinate2D"类型返回。

如何将"CLLocationCoordinate2D"的结果放入"CLLocation"中?

1个回答

45

明白了。

当地图视图改变区域时,从CLLocationCoordinate2D获取纬度和经度,并使用传入的纬度和经度创建一个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)

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接