这是我的代码,我想添加一个自定义图钉(.png 文件)而不是红色图钉。我尝试使用 MKPinAnnotationView 和 MKAnnotationView 但我无法添加坐标、字幕和标题。我是 iOS 开发的新手。
override func viewDidLoad() {
super.viewDidLoad()
// Handle the text field’s user input through delegate callbacks.
commentTextField.delegate = self
coreLocationManager.delegate = self
//desired accuracy is the best accuracy, very accurate data for the location
coreLocationManager.desiredAccuracy = kCLLocationAccuracyBest
//request authorization from the user when user using my app
coreLocationManager.requestWhenInUseAuthorization()
coreLocationManager.startUpdatingLocation()
dbRef = FIRDatabase.database().reference()
struct Location {
let title: String
let latitude: Double
let longitude: Double
let subtitle: String
}
// Locations array
let locations = [
Location(title: "Dio Con Dio", latitude: 40.590130, longitude: 23.036610,subtitle: "cafe"),
Location(title: "Paradosiako - Panorama", latitude: 40.590102, longitude: 23.036180,subtitle: "cafe"),
Location(title: "Veranda", latitude: 40.607740, longitude: 23.103044,subtitle: "cafe")
]
for location in locations {
let annotation = MKPointAnnotation()
annotation.title = location.title
annotation.coordinate = CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
annotation.subtitle = location.subtitle
map.addAnnotation(annotation)
}
}