gpt4 book ai didi

iphone - map View 删除多个图钉

转载 作者:行者123 更新时间:2023-12-03 21:19:06 25 4
gpt4 key购买 nike

我想在 map 上显示用户位置并放置一个图钉,但我的应用程序放置了两个相距一定距离的图钉。我想知道当新图钉被放置时如何删除旧图钉,以便应该有一个图钉 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;
}

最佳答案

当删除旧引脚的注释时,您使用新的引脚使用此功能

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

从 super View 中删除后调用加载 map ....再次使用

[self.view addSubview:mapView];

其中mapView是mapView的名称

关于iphone - map View 删除多个图钉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6688718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com