0

Im using the following method to show MKAnnotation View on my mapView. But wehn I do that the current location of the user is also given the same view as the other pins. How can I make the current location a Unique pin color

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] 
                                  initWithAnnotation:annotation 
                                  reuseIdentifier:@"currentloc"];
    //annView.pinColor = MKPinAnnotationColorGreen;

     UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
     myDetailButton.frame = CGRectMake(0, 0, 23, 23);
     myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
     myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    [myDetailButton addTarget:self 
                        action:nil/*@selector(checkButtonTapped:event:)*/ 
              forControlEvents:UIControlEventTouchUpInside];

    annView.rightCalloutAccessoryView = myDetailButton;

    annView.animatesDrop=NO;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}
Derek Beattie
  • 9,429
  • 4
  • 30
  • 44
banditKing
  • 9,405
  • 28
  • 100
  • 157
  • Unrelated to your question but: Instead of doing addTarget, handle the button press in the map view's own calloutAccessoryControlTapped delegate method which will give a reference to the annotation (see http://stackoverflow.com/questions/4565197/how-to-find-which-annotation-send-showdetails for example). Also, it's recommended to use dequeueReusableAnnotationViewWithIdentifier in viewForAnnotation to re-use views (see http://stackoverflow.com/questions/5421663/exc-bad-access-with-mkpinannotationview/5421847#5421847 for example). –  May 24 '11 at 01:34
  • Thanks Anna Karenina. I appreciate the input. – banditKing May 25 '11 at 00:15

1 Answers1

2

In your viewForAnnotation method, check to see if the annotation is an instance of MKUserLocation. If it is, return nil:

if ([annotation isMemberOfClass:[MKUserLocation class]]) return nil;
Anurag
  • 140,337
  • 36
  • 221
  • 257
CharlieMezak
  • 5,999
  • 1
  • 38
  • 54