[英]How to add properties to MGLAnnotation in Mapbox for iOS
How can I add a custom property such as 'Job' or 'Level' etc? 如何添加自定义属性,例如“作业”或“级别”等?
Currently builtins only allow for Title, Description, and Location. 当前内置的文件仅允许标题,描述和位置。
You have to subclass MGLAnnotation
and add custom properties, as following: 您必须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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.