1
我想在地圖上顯示用戶位置並放下一個針腳,但我的應用程序會丟棄兩個在一定距離處分開的針腳。我想知道當新針腳掉落時如何移除舊針腳,以便在那裏應該是在地圖上的一個引腳我的代碼是:地圖視圖丟棄多個針腳
-(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;
}