I need the annotation in the center of map just show me the title and no pin.
Is it possible to do so in Xcode? if yes how can I do this?
Yes, it's possible to create custom views instead of pins - see a great example MapCallouts from Apple, showing how to achieve this http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009746
in general, you need to implement a - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation method and return a custom view for you annotation (i believe the one with title and so on);
Related
I am using MKMapView in my iPhone app. I want to implement the pin annotation dragging feature. How can I implement this. The function setCoordinate: shows warning, MKPinAnnotationView may not responds to setCoordinate:. Please help.
That is due to that the MKPinAnnotationView doesn't implement the coordinate, however the annotation does.
Try using:
[pin.annotation setCoordinate:(CLLocationCoordinate2D)];
That should to the trick (given that you call your MKPinAnnotationView for "pin".
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
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.
i have an MKMapView and have a whole bunch of MKPinAnnotations being shown and all of them have call out feature which shows a more detail view depending on were the location is..
How can I implement a method that tells which pin has been pressed out of the group so it shows a more detail view about that location?
implement the MKMapView delegate:
- (void) mapView: (MKMapView *) mapView didSelectAnnotationView: (MKAnnotationView *) view
and you can do whatever you need in there.
But i think you are really after enabling the map callout accessory. See MapCallouts sample application http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009746
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