ios - 如何在地图上显示标注点信息?
问题描述
当我在地图上单击 Annotation 时,我希望有关单击位置的信息出现在底部的后视图中。我使用 Mapkit 创建地图
注释数组
let annotationLocations = [
["title":"X vet Clinic","latitude":39.895177 , "longitude":32.838194],
["title":"Y Vet Clinic","latitude": 39.894749, "longitude":32.841074],
["title":"Z Vet Clinic","latitude": 39.893615, "longitude":32.841476]
]
有了这个功能,我可以在地图上显示上面经纬度指定的位置
func createAnnotations(locations: [[String: Any]])
{
for location in locations{
let annotations = MKPointAnnotation()
annotations.title = location["title"] as? String
annotations.coordinate = CLLocationCoordinate2D(latitude: location["latitude"] as! CLLocationDegrees, longitude: location["longitude"] as! CLLocationDegrees)
myMap.addAnnotation(annotations)
}
}
解决方案
首先设置委托
myMap.delegate = self
然后实施
func mapView(_ mapView: MKMapView,didSelect view: MKAnnotationView) {
let ann = view.annotation as! MKPointAnnotation
// use ann
}
推荐阅读
- sql - 我想查询第一高薪和第二高薪之间的差异
- c++ - 停止在“稳态”上的 boost odeint 集成
- python - nonetype 对象仅来自 linux 没有属性“文本”
- angular - 允许在 cdkDropList 中水平定位
- python - 将对象转换为 float64 时的警告消息
- python - 如何在不知道 Flask 中的名称的情况下遍历请求中的文件
- python - 如何证明高斯金字塔的脉冲响应是尺度不变的?
- swift - Swift 属性包装器。通过引用分配
- java - Spring如何选择服务实现?
- swiftui - SwiftUI 中的列表视图在列表上方显示我无法摆脱的灰色区域