MKMapView当前位置显示为自定义引脚

adi*_*dit 11 iphone objective-c mkmapview ipad

我已经设置好我的MKMapView显示当前位置.我还为其他引脚实现了自定义引脚.然而,事实证明当前位置显示为自定义引脚,而我只是希望它是一个普通的蓝色圆圈(就像谷歌地图一样).

我在我的代码中定义了以下内容:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

如何防止当前位置显示为引脚?

Gyp*_*psa 24

你需要实现这个: -

- (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;
    }
}
Run Code Online (Sandbox Code Playgroud)