我有一个我想要调用的方法但是当我回到地图的中心时,它处于CLLocationCoordinate2D类型。
如何将CLLocationCoordinate2D的结果放入CLLocation?
答案 0 :(得分: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)
}