滴下多个针的地图视图

时间:2011-07-14 05:08:35

标签: iphone objective-c mapkit

我想在地图上显示用户位置并放下一个引脚,但是我的应用程序在两个距离处分开了两个引脚。我想知道如何在新引脚掉落时移除旧引脚,以便应该有一个引脚map我的代码是:

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

    MKPinAnnotationView *pinView = nil; 


    if(annotation != mapView.userLocation) 
    {



        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];



        pinView.pinColor = MKPinAnnotationColorGreen; 
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;


        UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(0, -200, 300, 37)];

        [label setNumberOfLines:4];


        [label setFont:[UIFont boldSystemFontOfSize:10]];

        [label setText:[address objectAtIndex:0]];



        SportUpAppDelegate *appDelegate =[[UIApplication sharedApplication]delegate];



        appDelegate.currentLocation=[address objectAtIndex:0];


        [label setTextAlignment:UITextAlignmentLeft];
        [label setBackgroundColor:[UIColor clearColor]];
        [label setTextColor:[UIColor whiteColor]];


        [pinView setLeftCalloutAccessoryView:label];
        [label release];




    } 
    else {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

1 个答案:

答案 0 :(得分:1)

在删除旧引脚的使用时使用新引脚使用此功能

[mapView removeAnnotations:mapView.annotations]; 
[mapView removeFromSuperview];
从superview中删除后

打电话给加载地图.... 再次使用

[self.view addSubview:mapView];

其中mapView是mapView的名称