मानचित्र पर उसे स्पर्श करने के लिए प्रतिक्रिया करने के लिए आप ऊपर viewDidLoad
में MapView
के लिए एक नल recogniser निर्धारित करने की आवश्यकता:
let gestureRecognizer = UITapGestureRecognizer(target: self, action:"handleTap:")
gestureRecognizer.delegate = self
mapView.addGestureRecognizer(gestureRecognizer)
नल संभाल कर रखें और टैप स्थान निर्देशांक मिलती है:
func handleTap(gestureReconizer: UILongPressGestureRecognizer) {
let location = gestureReconizer.locationInView(mapView)
let coordinate = mapView.convertPoint(location,toCoordinateFromView: mapView)
// Add annotation:
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
mapView.addAnnotation(annotation)
}
अब आपको एनोटेशन आकर्षित करने के लिए केवल एमकेमैपव्यू प्रतिनिधि कार्यों को लागू करना होगा। एक साधारण Google खोज आपको बाकी के बारे में मिलनी चाहिए।
स्विफ्ट 3 में आप के लिए यह काम करता है? – Neo42
मैंने स्विफ्ट 3 @ नियो 42 के लिए एक संपादन जोड़ा है। एक बार पीयर की समीक्षा के बाद आप इसे देख पाएंगे – KyleHodgetts