I have used a gesture recognizer and the boundingRect for a given overlay to determine when a user taps on it. However I would now like to make a callout appear over the overlay region that the user taps, just like how it is done for annotations. Must I create the overlays as annotations in order to accomplish this? Thanks.
Asked
Active
Viewed 1,941 times
1 Answers
2
Overlays are also annotation objects if you wish.
From the Location Awareness Programming Guide:
The MKOverlay protocol conforms to the MKAnnotation protocol. As a result, all overlay objects are also annotation objects and can be treated as one or both in your code. If you opt to treat an overlay object as both, you are responsible for managing that object in two places. If you want to display both an overlay view and annotation view for it, you must implement both the mapView:viewForOverlay: and mapView:viewForAnnotation: methods in your application delegate. It also means that you must add and remove the object from both the overlays and annotations arrays of your map.

petert
- 6,672
- 3
- 38
- 46
-
Thanks for the tip, however I am quite lost in how I would go about creating an overlay to be an annotation. Can you provide sample code in this area? Subclasses of MKAnnotationView usually have a UIImage as a variable and in the initWithAnnotation:reuseIdentifier: method there is no way to dynamically specify the width and height of the frame from the polygon's width and height(from the passed in annotation), is there? Thanks. – Stunner Feb 04 '11 at 12:23
-
The MapCallouts sample code might help? It shows MKAnnotations with custom callouts - http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html – petert Feb 04 '11 at 12:31
-
not work form me, I treat MKPolyLine as MKAnnotation, but failed. After I addAnnotation: to mapview, not trigger the call back - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id
)annotation – user501836 Apr 19 '12 at 07:46 -
Is the delegate a valid reference since `mapView:viewForAnnotation` is a method in delegate protocol (http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intf/MKMapViewDelegate) – petert Apr 19 '12 at 10:15
-
Could you detail the answer with some concrete example ? I am unable to display callout on top of the overlay. – michael-martinez Dec 29 '19 at 15:47