0
我通過CoreLocation
& CLLocation
得到當前位置。在MapKit上選擇一個位置並獲取經度和緯度
在另一個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)")
}
}
這是我迄今爲止,但它不工作...