开发者

Map view dropping multiple pins

I want to show user location on map and drop a pin but my app drops two pins separated at some distance.I want to know how can i remove the old pin when new pin is dropped so that there should be one pin on map My code is:

-(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;开发者_如何学Python
        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;
}


you use new pin when remove annonation of old pin use this function

[mapView removeAnnotations:mapView.annotations]; 
[mapView removeFromSuperview];

after remove from superview call the loading map.... again use

[self.view addSubview:mapView];

where mapView is name of mapView

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜