How do I show multiple MKAnnotations with the callout? - iphone

I want to add multiple MKAnnotations with the callout showing. I searched a few different threads on S.O and could not find a way to do it. Has anyone figured out how to add multiple pins with the callout visible?

Ok!
You should use [mapView selectAnnotation:currentAnnotation animated:FALSE]
But be sure to place this in the - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
delegate method
Trigger MKAnnotationView callout

Related

in mkmapview didSelectAnnotationView use can only touch a custom marker once, how to clear

I have custom markers in a map view. When the user touches one the app moves to another page. If the user returns to the map and touches the same item again
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
is not called until you touch somewhere in the map and then touch the marker again.
I tried deselecting the annotation view but the docs say not too, and in any case it didn't work.
Any ideas on how to fix this?
Instead of setting view.selected directly which the documentation says not to do, call the deselectAnnotation:animated: method instead:
[mapView deselectAnnotation:view.annotation animated:YES];
By the way, for the reverse, there's the selectAnnotation:animated: method.
Try using a UITapGestureRecognizer to recognize taps on the annotation view.

Show callout when tapping overlay

I have an MKMapView with several overlays. Works all just fine, and it's incredible how simple it works. There is, however, one thing I can't get to work. The idea is simple: when a user taps within the area that is covered by an overlay, a callout with some information about that overlay has to come up. The overlays are all MKPolygons, which follow the MKOverlay protocol and therefore the MKAnnotation protocol.
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.
This comes from the Apple docs. I tried something like this:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
aView.canShowCallout = YES;
}
But that doesn't seem to work. I've tried using gesture recognizers, but I have no idea how to show a callout other than by using the canShowCallOut property...
I suppose you have to add the MKOverlays as annotations also
[self.mapView addAnnotations:myOverlays];
Then return a MKAnnotationView in (mapView:viewForAnnotation) that's not hidden, either a graphic (tap-able) or zero alpha view. Next, add a UITapGestureRecognizer for each MKOverlayView, make sure it works with the map's gestures (UIGestureRecognizerDelegate implementation for simultaneous recognition). Finally when your gesture recognizer fires do this
[self.mapView setSelectedAnnotations:[NSArray arrayWithObject:myOverlayView.overlay]];
I'm not certain that this actually triggers the callOut showing though.
Also make sure your return title and/or subtitle from your overlay object.

callout bubble MKMapView move problem

Im currently developping an App which uses a MKMapView. Wenn the map is moved I perform server request to get new Annotations based on the coordinates.
Wenn an annotation is clicked it sometines moves the map. In this case i don't want to perform a Request.
Has somebody a solution how to know if it was an callout buble which moved the map ?
I tried with - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{ without success !
Look at this answer where I explain several methods to track that the MKMapView has moved.
That answers a different problem, but I think that might help you.

Show callout bubble without user interaction

How to show callout bubble without the user tapping on the pin ??
(Assuming you're talking about annotations on MKMapView)
Call [mapView selectAnnotation:yourAnnotation animated:YES]; with your annotation object
It can be done as Vladimir said, but I think you need to do it after the MKAnnotationView related to your annotation is shown.
You can use the method below (which is a method defined in MKMapViewDelegate) to get informed when an annotation view is added to your MKMapView:
-(void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
So, basically you need to invoke the method mentioned by Vladimir
[mapView selectAnnotation:yourAnnotation animated:YES];
in the implementation of the delegate method I mentioned above

What is the delegate method that is called when an MKPinAnnotationView is touched?

I have been searching for this all night and I have just so frustrated. When a MKPinAnnotationView is clicked, the name and the subtitle comes up. I also want to center that point on the view. I figured there was some method I had to override because the information that pops up happened without me having to code it. Hopefully this was clear enough for you all.
And in the mean time, I feel like there is some hidden guide on this use of MKMaps and other classes. Either that or it is terribly documented because I am having a lot of trouble finding information. Thanks.
Have you tried overriding setSelected:animated:? (defined in MKAnnotationView)
-(void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)view{
}
This is the method that is called when you tap on a pin.