地图视图删除了多个图钉 [英] 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;
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];
其中mapView是mapView的名称
where mapView is name of mapView
这篇关于地图视图删除了多个图钉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文