【发布时间】:2017-08-06 01:38:01
【问题描述】:
我实现了通过CoreLocation 和CLLocation 获取当前位置。
在另一个 UIViewController 中,我想在 MapKit 上选择一个位置,并从 MapKit 获取纬度和经度。我搜索了很多,但我发现了一些使用 Objective-C 的课程。
或者有没有 Swift 的课程?
class CustomLocationVC: UIViewController, MKMapViewDelegate, UIGestureRecognizerDelegate {
@IBOutlet weak var mapKitC: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapKitC.delegate = self
let gestureZ = UILongPressGestureRecognizer(target: self, action: #selector(self.revealRegionDetailsWithLongPressOnMap(sender:)))
view.addGestureRecognizer(gestureZ)
}
@IBAction func revealRegionDetailsWithLongPressOnMap(sender: UILongPressGestureRecognizer) {
if sender.state != UIGestureRecognizerState.began { return }
let touchLocation = sender.location(in: mapKitC)
let locationCoordinate = mapKitC.convert(touchLocation, toCoordinateFrom: mapKitC)
print("Tapped at lat: \(locationCoordinate.latitude) long: \(locationCoordinate.longitude)")
}
}
这是我目前所拥有的,但它不起作用......
【问题讨论】:
标签: ios swift mkmapview mapkit