如何在Mapbox for iOS中向MGLAnnotation添加属性

时间:2018-01-18 22:26:18

标签: objective-c swift mapbox

如何添加自定义属性,例如“作业”或“等级”等?

目前,builtins仅允许标题,描述和位置。

1 个答案:

答案 0 :(得分:2)

您必须继承MGLAnnotation并添加自定义属性,如下所示:

class MyAnnotation: NSObject, MGLAnnotation {

    var coordinate: CLLocationCoordinate2D
    var title: String?
    var subtitle: String?

    // Custom properties
    var job: Job?
    var level: Level?

    init(coordinate: CLLocationCoordinate2D, title: String?, subtitle: String?) {
        self.coordinate = coordinate
        self.title = title
        self.subtitle = subtitle
    }
}