Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 放置多个管脚的地图视图_Iphone_Objective C_Mapkit - Fatal编程技术网

Iphone 放置多个管脚的地图视图

Iphone 放置多个管脚的地图视图,iphone,objective-c,mapkit,Iphone,Objective C,Mapkit,我想在地图上显示用户位置并放置一个pin,但我的应用程序放置了两个相隔一定距离的pin。我想知道如何在放置新pin时移除旧pin,以便在地图上应有一个pin。我的代码是: -(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: (id <MKAnnotation>)annotation { MKPinAnnotationView *pinView = nil; if(annotation

我想在地图上显示用户位置并放置一个pin,但我的应用程序放置了两个相隔一定距离的pin。我想知道如何在放置新pin时移除旧pin,以便在地图上应有一个pin。我的代码是:

-(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;
}
-(MKAnnotationView*)地图视图:(MKMapView*)mV视图用于注释:
(id)注释{
MKPinAnnotationView*pinView=nil;
if(注释!=mapView.userLocation)
{
静态NSString*defaultPinID=@“com.invasivecode.pin”;
pinView=(MKPinAnnotationView*)[mapView出列重用AnnotationViewWithIdentifier:defaultPinID];
如果(pinView==nil)pinView=[[[MKPinAnnotationView alloc]
initWithAnnotation:annotation重用标识符:defaultPinID]autorelease];
pinView.pinColor=MKPinAnnotationColorGreen;
pinView.canShowCallout=是;
pinView.animatesDrop=是;
UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(0,-200300,37)];
[label setNumberOfLines:4];
[label setFont:[UIFont boldSystemFontOfSize:10];
[label setText:[地址对象索引:0]];
SportUpAppDelegate*appDelegate=[[UIApplication sharedApplication]delegate];
appDelegate.currentLocation=[地址对象索引:0];
[标签setTextAlignment:UITextAlignmentLeft];
[标签setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[pinView setLeftCalloutAccessoryView:标签];
[标签发布];
} 
否则{
[mapView.userLocation setTitle:@“我在这里”];
}
返回pinView;
}

删除旧pin的注释时使用新pin使用此功能

[mapView removeAnnotations:mapView.annotations]; 
[mapView removeFromSuperview];
从superview中删除后 调用加载映射。。。。 再利用

[self.view addSubview:mapView];
其中mapView是mapView的名称