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)
swift地图定位(十三)大头针系统视图
最新推荐文章于 2024-08-14 17:22:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)