I am trying to detect the location of a tap on a MKMapVIew to place a pin on that location. Is there an event I can capture which will give me this information?
Here is the answer translated to MonoTouch in C#
Add this to the ViewController holding the MKMapView
public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        UILongPressGestureRecognizer sgr = new UILongPressGestureRecognizer ();
        sgr.AddTarget (this, new MonoTouch.ObjCRuntime.Selector ("LongPressGesture"));
        sgr.MinimumPressDuration = 1f;
        sgr.Delegate = new LongPressRecognizerDelegate ();
        this.View.AddGestureRecognizer (sgr);
    }
    [Export("LongPressGesture")]
    public void Handle (UIGestureRecognizer recognizer)
    {
        //http://freshmob.com.au/mapkit/mapkit-tap-and-hold-to-drop-a-pin-on-the-map/
        //and
        //http://inxunxa.wordpress.com/2011/03/10/monotouch-longpress/
        if (recognizer.State != UIGestureRecognizerState.Began)
            return;
        // get the point of the   action
        PointF point = recognizer.LocationInView (this.View);
        CLLocationCoordinate2D coord = this.map.ConvertPoint (point, this.map);
        //Add pin annoation here
        LocationAnnotation ann = new LocationAnnotation (new LocationEntity (coord));
        this.map.AddAnnotation (ann);
    }
    public class LongPressRecognizerDelegate : MonoTouch.UIKit.UIGestureRecognizerDelegate
    {
        public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
        {
            return true;
        }
    }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With