我正在创建一个标记应用程序,用户可以在其中将街头艺术标记到地图上。我希望用户能够单击图钉 (i) 标注按钮并被带到 Apple Maps。
这个函数应该允许这种情况发生但是我得到一个错误“实例成员'坐标'不能用于类型'艺术'” -
函数 openInMaps() {
let regionDistance:CLLocationDistance = 1000
let coordinates = art.coordinate
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates!, regionDistance, regionDistance)
let options = [
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
]
let placemark = MKPlacemark(coordinate: coordinates!, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = art.name
mapItem.openInMaps(launchOptions: options)
}
这是我的艺术课——
import Foundation
import FirebaseDatabase
import CoreLocation
class art {
let coordinate: CLLocationCoordinate2D!
var name: String!
var location: String!
var type: String!
var ref: FIRDatabaseReference?
init(snapshot: FIRDataSnapshot) {
let snapshotValue = snapshot.value as! [String: Any]
ref = snapshot.ref
name = snapshotValue["name"] as! String
location = snapshotValue["location"] as! String
coordinate = CLLocationCoordinate2D(latitude: snapshotValue["lat"] as! Double, longitude: snapshotValue["lng"] as! Double)
// type = snapshotValue["type"] as! String
}
}
如果有人指出我正确的方向或告诉我我做错了什么,那就太好了!谢谢。