4

这是我-mapView:viewForAnnotation创建注释视图时丢弃引脚的方法。但是当我设置mapView.showsUserLocation = YES;-viewDidLoad,我在无限循环(预期 - 在模拟器中)而不是正常的蓝点上掉了一个针。

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
     MKAnnotationView *anno = nil;
     //create a pin annotation view
MKPinAnnotationView  *pin=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"]autorelease];

    [pin setPinColor:MKPinAnnotationColorRed];
    pin.animatesDrop=YES;
    pin.canShowCallout = YES;
    pin.calloutOffset = CGPointMake(-5, 5);
    anno = pin;
    return anno;
}

我怎样才能让它放下大头针并显示蓝点?

谢谢

4

3 回答 3

24

修复起来真的很简单,虽然不确定这是否是正确的方法......

if (annotation == mapView.userLocation){
    return nil; //default to blue dot
}
于 2009-12-05T19:24:18.853 回答
0

与其他答案类似,这里有一些接近的东西:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{
    NSString *annotationType = [NSString stringWithCString:object_getClassName(annotation)];
    if ([annotationType compare:@"NSKVONotifying_MKUserLocation"] == 0)
        return nil;
    ...
}

当然,使用这样的东西需要您自担风险。如果 Apple 决定更改该名称,它可能会在明天停止工作。

于 2009-12-06T06:07:05.567 回答
0

您经常使用自己的注释类来查找与注释相关的信息。在这种情况下,要仅处理您自己的注释,请使用类似

if ([annotation isKindOfClass:[MapLocation class]]) {}
于 2010-08-03T09:43:33.650 回答