当我更新注释坐标时,只有标记在移动,标题停留在先前的位置,这是我更新坐标的部分:
for annotation in self.mapView.annotations
{
if let ann = annotation as? Artwork
{
if user.id == ann.id
{
if ann.coordinate.latitude != user.latitude! && ann.coordinate.longitude != user.longitude!
{
let userCoordinates = CLLocationCoordinate2D(latitude: user.latitude!, longitude: user.longitude!)
ann.coordinate = userCoordinates
}
}
}
}
这是我的美术课:
import Foundation
import MapKit
class Artwork: NSObject, MKAnnotation
{
let title: String?
dynamic var coordinate: CLLocationCoordinate2D
let id: Int
init(title: String, coordinate: CLLocationCoordinate2D, id: Int)
{
self.title = title
self.coordinate = coordinate
self.id = id
super.init()
}
}
有人对标题为何保留在先前位置有想法吗?
答案 0 :(得分:0)
这是工作代码:
ann.title = username
ann.coordinate = userCoordinates
//And in the class I modified to this:
let id: Int
dynamic var title: String?
dynamic var coordinate: CLLocationCoordinate2D