Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKMapView current location showing as custom pins

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?

like image 625
adit Avatar asked Sep 23 '11 05:09

adit


2 Answers

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;
    }
}
like image 64
Gypsa Avatar answered Nov 15 '22 13:11

Gypsa


For Swift:

if annotation is MKUserLocation {
    return nil
}
like image 34
MrRhoads Avatar answered Nov 15 '22 13:11

MrRhoads