I have an iOS
app where I need to interfere with a map.
After searching a bit I came to the conclusion that I have to use an MKMapView
object and probably implement the MKMapViewDelegate
protocol.
I am now wondering how I can capture the touch point (meaning longitude and lattitude) when the user taps on the map. I suppose there is a much better way than fiddling around with a home made UITapGestureRecognizer
.
To make it clear and simple, I have this kind of code to start with:
import UIKit
import CoreLocation
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate,
screenSize: CGRect = UIScreen.mainScreen().bounds,
locationManager = CLLocationManager()
.........
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
.........
let mapView = MKMapView(frame: CGRect(origin: CGPoint(x: 0.0, y: 20.0),
size: CGSize(width: screenSize.width,
height: screenSize.height-70.0)))
mapView.delegate = self
self.view.addSubview(mapView)
}
.........
}
My question is: what do I have to do to handle the tap of the user on the mapView object? Though I looked for the anwer before writing this post, I came with no clear solution.