Kim*_*rly 5 objective-c cllocationmanager ios parse-platform
是否可以将PFGeoPoint与Parse转换为CLLocation?
原因是我试图从PFGeoPoint获取地点名称,如下所示:
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);
}
}];
Run Code Online (Sandbox Code Playgroud)
我明白的错误是:
Incompatiable pointer types sending 'PFGeoPoint *' to parameter of type 'CLLocation *'
Run Code Online (Sandbox Code Playgroud)
正如Wain所说,没有方便的方法可以转换PFGeoPoint为a,CLLocation但是你可以自己制作并PFGeoPoint使用以下方法进行扩展
import Parse
extension PFGeoPoint {
func location() -> CLLocation {
return CLLocation(latitude: self.latitude, longitude: self.longitude)
}
}
Run Code Online (Sandbox Code Playgroud)
现在您可以通过执行操作轻松返回CLLocation对象
let aLocation: CLLocation = yourGeoPointObject.location()
Run Code Online (Sandbox Code Playgroud)
你需要明确创建CLLocation使用实例initWithLatitude:longitude:与latitude和longitude从PFGeoPoint.只有一种方便的方法来创建PFGeoPointa CLLocation,而不是相反.
| 归档时间: |
|
| 查看次数: |
2464 次 |
| 最近记录: |