import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
lazy var geoCoder: CLGeocoder = {
return CLGeocoder()
}()
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
let point = touches.first?.location(in: mapView)
let coordinate = mapView.convert(point!, toCoordinateFrom: mapView)
let annotation = addAnnotation(coordinate, title: "title", subTitle: "subTitle")
let location = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
geoCoder.reverseGeocodeLocation(location) { (pls: [CLPlacemark]?, error: Error?) -> Void in
if error == nil {
let pl = pls?.first
print(pl)//Optional
swift地图定位(十四)使用 MKAnnotationView自定义大头针视图
最新推荐文章于 2024-09-19 10:29:13 发布
本文介绍如何在Swift中使用MKAnnotationView自定义地图上的大头针视图,包括设置大头针图片、中心偏移量、弹框及左右侧视图,并实现大头针拖动功能。
摘要由CSDN通过智能技术生成