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(祖冲之路705号, 中国上海市浦东新区张江镇祖冲之路705号 @ <+31.20264860,+121.
swift地图定位(十四)使用 MKAnnotationView自定义大头针视图
最新推荐文章于 2020-11-11 18:49:11 发布