2

I have an iPhone app that zooms to the nearest city of the user's location and I want the user to be able to double tap on the userLocation annotation and have the map zoom into about a block or so.

How do I get the userLocation annotation to recognize that it's being tapped?

Dinesh Raja
  • 8,501
  • 5
  • 42
  • 81
barndog
  • 6,975
  • 8
  • 53
  • 105

2 Answers2

6
- (void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)mapView2
{
    id<MKAnnotation> annotation = mapView2.annotation;
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
          // this is where you can find the annotation type is whether it is userlocation or not...
     }
}

the above method is a delegate method and you need to add MKMapViewDelegate in your interface file

Dinesh Raja
  • 8,501
  • 5
  • 42
  • 81
  • Well MapAnnotation isn't a type. MKAnnotation is but whenever I try to declare the MKAnnotation object I get an error at says Unknown Type 'MKAnnotation' – barndog Oct 30 '12 at 15:18
0

Here's the code in Swift 4:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if view.annotation is MKUserLocation {
        // You tapped on the user location
    }
}