0
我不完全知道這是否已經回答過,但我一直無法找到它,所以我想我會發佈一個問題。當我改變它的座標時,自定義MKAnnotation消失
我有一個自定義MKAnnotation,顯示了完美的罰款,如果我使用的座標,如:「74.8044595495237 -21.7716836352598」
var currLat: Double! = 74.8044595495237
var currLong: Double! = -21.7716836352598
let egg: EggPin = EggPin(coordinate: CLLocationCoordinate2DMake(currLat, currLong), title: "Egg", subtitle: "This is an egg")
這工作得很好。自定義的MKAnnotation在地圖上顯示出來,一切都很好,很棒。但是,當我改變EggPin的座標由currLat和currLong減去1.0,如下所示:
var currLat: Double! = 74.8044595495237
var currLong: Double! = -21.7716836352598
let egg: EggPin = EggPin(coordinate: CLLocationCoordinate2DMake(currLat - 1.0, currLong - 1.0), title: "Egg", subtitle: "This is an egg")
的MKAnnotation消失。我是MapKit的新手,所以我覺得我必須錯過一些關於設置座標的簡單東西。下面是我EggPin類是否會有所幫助:
import Foundation
import MapKit
class EggPin: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?
init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
super.init()
}
}