import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
lazy var geoCoder: CLGeocoder = {
return CLGeocoder()
}()
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(金桥谷创意园, 中国上海市浦东新区金桥镇金高路2216弄35号 @ <+31.26179100,+121.60547600&
swift地图定位(十二)大头针的基本使用
最新推荐文章于 2024-07-14 18:17:42 发布