put CLLocationCoordinate2D into CLLocation for Swift
Asked Answered
S

1

22

I have a method I want to call however when I get back the center of the map, it is in CLLocationCoordinate2D type.

How do I put the results of CLLocationCoordinate2D into CLLocation?

Spectrogram answered 11/11, 2014 at 18:22 Comment(0)
S
45

Figured it out.

When mapView changes region, get the Lat and Lon from CLLocationCoordinate2D and create a CLLocation variable with the lat and lon passed in.

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)

}
Spectrogram answered 11/11, 2014 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.