1

我在地图上放置了大头针,当前位置以蓝点显示。我补充说:

- (MKAnnotationView *)mapView:(MKMapView *)amapView viewForAnnotation:(id<MKAnnotation>)annotation{


    NSString *identifier =@"mypin";
    MKPinAnnotationView *pin = (MKPinAnnotationView *) [amapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    if(pin ==nil){
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
    }else{
        pin.annotation = annotation;
    }

    UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    myDetailButton.frame = CGRectMake(0, 0, 23, 23);
    myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    [myDetailButton addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

    pin.rightCalloutAccessoryView = myDetailButton;
    pin.enabled = YES;
    pin.animatesDrop = TRUE;
    pin.canShowCallout = YES;

    return pin;
}

但是现在当前位置是一个大头针而不是蓝点。如何阻止当前位置的注释成为图钉并将其保持为蓝点。

请问有什么帮助吗?

4

3 回答 3

1

“蓝点”是一个特殊的注释,一个MKUserLocation. 所以,在你的 中viewForAnnotation,只需在开头添加以下两行,告诉 iOS 使用标准的“蓝点”作为用户位置注释:

if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

通过返回nil,您将告诉 iOS 对用户位置使用默认的“蓝点”注释。

有关实践中的示例,请参阅Location Awareness Programming Guide的从您的委托对象创建注释视图部分中的代码示例。

于 2013-06-28T05:42:03.647 回答
0

简单的 :

- (MKAnnotationView *)mapView :(MKMapView *)maapView viewForAnnotation:(id <MKAnnotation>) annotation{
    @autoreleasepool {


    if (annotation == maapView.userLocation)
    {
        // This code will execute when the current location is called.
        return nil;
    }
    else
    {
        MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
        annView.pinColor = MKPinAnnotationColorPurple;
        annView.animatesDrop=YES;
        annView.canShowCallout = YES;
        annView.calloutOffset = CGPointMake(-5, 5);
        UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];

        annView.rightCalloutAccessoryView = rightButton;
        return annView;
    }

}
}
于 2013-06-28T05:50:33.350 回答
0

干净而迅速的 (3) 方式

if annotation is MKUserLocation {
    return nil
}
于 2017-05-02T15:12:56.410 回答