在我的應用程序中,用戶保存一些數據,包括地圖座標。在我的代碼中,一個別針被放在保存的地圖座標上。這裏是我的代碼 -爲什麼我的MKPointAnnotation在視圖加載時不顯示?
override func viewDidLoad() {
super.viewDidLoad()
self.mapView.delegate = self
// Data loading
itemNameTextField.delegate = self
itemDescriptionLabel.delegate = self
itemLocationTextView.delegate = self
// Press recognizer
if let item = item {
itemNameTextField.text = item.itemName
itemDescriptionLabel.text = item.itemDescription
itemLocationTextView.text = item.itemPlace
let dropPin = MKPointAnnotation()
dropPin.coordinate = mapView.convert(item.mapPoint, toCoordinateFrom: mapView)
dropPin.title = "Location of \(item.itemName)"
self.mapView.addAnnotation(dropPin)
print("Set the location of item pin to \(String(describing: dropPin.coordinate))")
}
// Styles
itemInfoView.layer.cornerRadius = 3
itemInfoView.layer.shadowColor = UIColor(red:0/255.0, green:0/255.0, blue:0/255.0, alpha: 1.0).cgColor
itemInfoView.layer.shadowOffset = CGSize(width: 0, height: 1.75)
itemInfoView.layer.shadowRadius = 1.7
itemInfoView.layer.shadowOpacity = 0.45
itemLocationView.layer.cornerRadius = 3
itemLocationView.layer.shadowColor = UIColor(red:0/255.0, green:0/255.0, blue:0/255.0, alpha: 1.0).cgColor
itemLocationView.layer.shadowOffset = CGSize(width: 0, height: 1.75)
itemLocationView.layer.shadowRadius = 1.7
itemLocationView.layer.shadowOpacity = 0.45
locationAdressTextview.layer.cornerRadius = 2
locationAdressTextview.layer.shadowColor = UIColor(red:0/255.0, green:0/255.0, blue:0/255.0, alpha: 1.0).cgColor
locationAdressTextview.layer.shadowOffset = CGSize(width: 0, height: 1.50)
locationAdressTextview.layer.shadowRadius = 1.6
locationAdressTextview.layer.shadowOpacity = 0.3
}
我知道,應用程序確實保存銷座標作爲CGPoint
,我知道它從一個CGPoint
將其轉化爲CLLocationCoordinate2D
,因爲print
報表一放置。但是,當屏幕加載時,print語句會顯示一個有效的座標,但地圖上沒有pin,並且不會出現錯誤。有人能幫幫我嗎?謝謝!
如果您需要澄清,或者您需要我添加更多的代碼,只需發表評論。 –