gpt4 book ai didi

ios - 注释 map View (自定义标记)在 swift IOS 中不起作用

转载 作者:行者123 更新时间:2023-11-30 11:51:50 25 4
gpt4 key购买 nike

//我的 View Controller 代码
//AddAnnotation 和 MApView 但我不知道问题所在,如果可能的话请上传演示代码,因为我是 iOS 新手

private func addAnnotation(coordinate coordinate:CLLocationCoordinate2D, title: String, subtitle: String) {
let coordinatesss = CLLocationCoordinate2D(latitude: 28.56785, longitude: 78.54255)

addAnnotation(coordinate: coordinates , title: "titles" , subtitle: "subtitles")

mapView.addAnnotation(annotation)
}

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation { return nil }
let coordinates = CLLocationCoordinate2D(latitude: 28.56785, longitude: 78.54255)

let identifier = "CustomAnnotation"

var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)

if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView!.canShowCallout = true
annotationView!.image = UIImage(named: "star.png")!
} else {
annotationView!.annotation = annotation
}

return annotationView
}

最佳答案

尝试以下代码

override func viewDidLoad() {
super.viewDidLoad()

let coordinate = CLLocationCoordinate2D(latitude: 28.56785, longitude: 78.54255)
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotation.title = "titles"
annotation.subtitle = "subtitles"
self.mapView.addAnnotation(annotation)
}

关于ios - 注释 map View (自定义标记)在 swift IOS 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48262248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com