ios - 在图像中添加 MKPointAnnotation 时蓝点未移除

标签 ios mkmapview

我正在使用 MKMapView 添加 MKPointAnnotation 注释。

我已将图像提供给 MKPointAnnoation,但蓝点未删除。

-(void)updateMarkerWithUserLocation
{
    NSString *name=  [[NSUserDefaults standardUserDefaults]valueForKey:@"userName"];

    for (MKPointAnnotation *annotation in _mapView.annotations)
    {
        [_mapView removeAnnotation:annotation];
    }
    NSNumber * latitude = [NSNumber numberWithFloat:[[NSUserDefaults standardUserDefaults]floatForKey:@"currentLatitude"]];
    NSNumber * longitude = [NSNumber numberWithFloat:[[NSUserDefaults standardUserDefaults]floatForKey:@"currentLongitude"]];

    ////******   to add my location in the map of type MKPointAnnotation

    CLLocationCoordinate2D annotationCoord;

    annotationCoord.latitude = [latitude floatValue];
    annotationCoord.longitude = [longitude floatValue];

    MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
    annotationPoint.coordinate = annotationCoord;

    StrLocality=[[NSUserDefaults standardUserDefaults]valueForKey:@"StrLocality"];
    annotationPoint.title = name;
    annotationPoint.subtitle=StrLocality;

    [_mapView addAnnotation:annotationPoint];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKPointAnnotation class]])
    {
        // Try to dequeue an existing pin view first.
        MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
        if (!pinView)
        {
            pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
            //pinView.animatesDrop = YES;
            pinView.canShowCallout = YES;
            pinView.image = [UIImage imageNamed:@"user_location.png"];
            // pinView.calloutOffset = CGPointMake(5, 32);
        } else {
            pinView.annotation = annotation;
        }
        return pinView;
    }

    return nil;
}

enter image description here

最佳答案

蓝点不会被删除,因为您已经告诉 map 显示用户的位置,并且在您告诉它停止显示用户的位置之前,它将继续显示蓝点。 如果您想要这样做,请在代码中的某个位置添加 [mapView setShowsuserLocation:NO] 将其关闭。

关于ios - 在图像中添加 MKPointAnnotation 时蓝点未移除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20877717/

相关文章:

ios - 如何设置 MKMapView activityType?

ios - 如何像 Reminder App 一样在 pin 周围制作可拉伸(stretch)的圆形区域

php - 在 php 中运行 xcodebuild

ios - 如何设置地址簿访问请求警报 View 的文本?

ios - 针对不同的屏幕尺寸调整图像大小而不会降低质量。最好的方法是什么?

cocoa-touch - 如何在不使用 setCoordinate 的情况下更新注释?

swift - “MKMapRectIsNull”已被属性 'MKMapRect.isNull' 取代

ios - Interface Builder Storyboard 编译失败?

ios - 从后台返回时pushViewController

swift - 如何最好地从 Web 服务器加载 MapView 的位置