当我改变它的坐标时,自定义MKAnnotation消失

时间:2016-08-12 22:24:34

标签: ios swift mapkit 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出现在地图上,一切都很好,花花公子。但是,当我通过从currLat和currLong中减去1.0来改变EggPin的坐标时,如下所示:

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()

    }    
}

0 个答案:

没有答案