How to convert PFGeoPoint to CLLocation

Is it possible to convert PFGeoPoint from Parse to CLLocation?

The reason is because I'm trying to get place names from PFGeoPoint like this:

CLGeocoder *geocoder; CLPlacemark *placemark; PFGeoPoint *point = [object objectForKey:@"location"]; [geocoder reverseGeocodeLocation:point completionHandler:^(NSArray *placemarks, NSError *error) { NSLog(@"Found placemarks: %@, error: %@", placemarks, error); if (error == nil && [placemarks count] > 0) { placemark = [placemarks lastObject]; NSLog(@"%@", placemarks); } }]; 

The error I am getting is obviously:

 Incompatiable pointer types sending 'PFGeoPoint *' to parameter of type 'CLLocation *' 
+5
source share
4 answers

You need to explicitly create an instance of CLLocation using initWithLatitude:longitude: with latitude and longitude from PFGeoPoint . There is only a convenient method for creating PFGeoPoint from CLLocation , and not vice versa.

+5
source

As Wayne said, there is no convenient way to convert from PFGeoPoint to CLLocation , however you can make your own and extend PFGeoPoint using the following

 import Parse extension PFGeoPoint { func location() -> CLLocation { return CLLocation(latitude: self.latitude, longitude: self.longitude) } } 

Now you can easily return the CLLocation object by doing

 let aLocation: CLLocation = yourGeoPointObject.location() 
+6
source

Based on Justin Oroz's answer (see answer below): It might also be a good idea to create an extension on the CLLocation side so that it can be created using the handy init that PFGeoPoint receives:

 extension CLLocation { convenience init(geoPoint: PFGeoPoint) { self.init(latitude: geoPoint.latitude, longitude: geoPoint.longitude) } } 
+2
source

You can always get PFGeoPoint and then add it to CLLocationCoordinate2D as follows:

 //get all PFObjects let parseLocation = ParseObject["location"] let location:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: parseLocation.latitude, longitude: parseLocation.longitude) 
0
source

Source: https://habr.com/ru/post/1209792/


All Articles