Alex Rivera | Logout

MKMapView current location showing as custom pins

Asked 2011-09-23T05:24:55.010
11

I have set so that my MKMapView shows the current location. I also have a custom pin implemented for other pins. However, it turns out the current location shows as a custom pin, whereas I just wanted it to be a regular blue circle (like what google map has).

I have defined the following in my code:

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"];
    if (pin == nil)
    {
        pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease];
    }
    else
    {
        pin.annotation = annotation;
    }

    [pin setImage:[UIImage imageNamed:@"TestPin.png"]];
    pin.canShowCallout = YES;
    pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    return pin;
}

How can I prevent the current location to show up as a pin?

Edit
Report

1 Answer

24

you need to implement this:-

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation
{        
    if (annotation == mapView.userLocation)
    {
       return nil;
    }
    else
    {
       MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"];
       if (pin == nil)
       {  
          pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease];
       }
       else
       {
          pin.annotation = annotation;
       }           

       [pin setImage:[UIImage imageNamed:@"TestPin.png"]];
       pin.canShowCallout = YES;
       pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
       return pin;
    }
}
answered 2011-09-23T05:42:37.587

Your Answer