swift 中具有纬度和经度的 CLLocation 对象

CLLocation object in swift with latitude and longitude

我会尝试设置 CLLocation 对象的纬度和经度 属性 但我在 运行 上收到此错误:

Cannot convert CLlocation object to EMTrackPoint Object

for element in objectsArray {
    let item = CLLocation(latitude: element.latitude, longitude: element.longitude) as! EMTrackPoint

    item.mElevation = element.ele
    item.mOrientation = element.orientation
    item.mDate = Date()
    if element.poiActive != ""{
         GPXActive.add(element.poiActive.components(separatedBy: ","))
    }
    GPXDanger.add(element.dangerActive.components(separatedBy: ","))
    item.mActivePOIs = GPXActive
    item.mActiveDangers = GPXDanger
    GPXPoints.add(item)
}

Objective C中的EMTrackPointclass:

@interface EMTrackPoint : CLLocation

@property (nonatomic, assign) double mElevation;
@property (nonatomic, retain) NSDate *mDate;
@property (nonatomic, retain) NSMutableArray *mActivePOIs;
@property (nonatomic, retain) NSMutableArray *mActiveDangers;
@property (nonatomic, assign) double mOrientation;
@property (nonatomic, assign) double mSpeed;

请帮忙。

每个 EMTrackPoint 也是一个 CLLocation 那么为什么不首先初始化一个 EMTrackPoint 实例而不是进行类型转换:

for element in objectsArray {
    let item = EMTrackPoint(latitude: element.latitude, longitude: element.longitude)
    item.mElevation = element.ele
    item.mOrientation = element.orientation
    item.mDate = Date()
    ...