GendoIkari
GendoIkari

Reputation: 11914

MKMapView / MKOverlay - allow user to define overlay coordinates

I am trying to allow the user to define a border for an overlay. This seems like it should be a simple thing; but I can't even find out how to know when the user is touching the map. I would have thought that the UIMapViewDelegate would have methods to respond to the user's interactions, but it doesn't seem to. In the Google Maps app, it drops a pin when you hold on a spot; I'm guessing that would be the first step to having the user define an overlay.

It looks like the UILongPressGestureRecognizer would provide what I want; but don't quite understand how you add a GestureRecognizer to the MapView. I've read through the MKMapView and UIGestureRecognizer documentation; what am I missing? Thanks.

Upvotes: 0

Views: 1008

Answers (1)

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

Any UIView supports having a gesture recognizer added to it with the -addGestureRecognizer: method. That might not be the best approach here, though: if you'd like to replicate the Maps behavior, you can use an MKPinAnnotationView with its draggable property set to YES, then update your overlay's boundaries to fit the annotation's position when the drag ends (i.e. when the map view calls its -mapView:annotationView:didChangeDragState:fromOldState: delegate method). Note that whatever annotation class you're using needs to implement a -setCoordinate: method, as defined in the MKAnnotation protocol, for pin dragging to work.

Upvotes: 1

Related Questions