【问题标题】:showsUserLocation returns pin instead of blue dot in iPhone simulatorshowUserLocation 在 iPhone 模拟器中返回 pin 而不是蓝点
【发布时间】:2010-12-23 14:44:02
【问题描述】:

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

- (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;
}

我怎样才能让它放下图钉并显示蓝点?

谢谢

【问题讨论】:

    标签: iphone mkmapview mkpinannotationview


    【解决方案1】:

    真的很容易修复,虽然不确定这是否是正确的方法......

    if (annotation == mapView.userLocation){
        return nil; //default to blue dot
    }
    

    【讨论】:

    • 你一定想知道为什么这是正确的方法,但我们不能setUserLocation ....
    【解决方案2】:

    与另一个答案类似,这里有一些接近:

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

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

    【讨论】:

      【解决方案3】:

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

      if ([annotation isKindOfClass:[MapLocation class]]) {}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多