任何演示示例多重贴图使用plist?

我想使用地图注释,我有我有数据的plist列表,我想使用注释在地图上显示数据。 我有示例MapCallsout示例,但我必须在地图上阅读plist?

首先从Plist中获取所有位置并将其放入一个数组中。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; NSString *fooPath = [documentsPath stringByAppendingPathComponent:@"yourPlistFile.plist"]; NSLog(fooPath); NSArray *contentArray = [NSArray arrayWithContentsOfFile:fooPath]; NSLog(@"%@",contentArray); 

使用下面的代码在地图上显示多个注释。

 NSMutableArray *toRemove = [NSMutableArray arrayWithCapacity:10]; for (id annotation in yourMapView.annotations) if (annotation != yourMapView.userLocation) [toRemove addObject:annotation]; [yourMapView removeAnnotations:toRemove]; yourMapView.delegate = self; [yourMapView setMapType:MKMapTypeStandard]; MKCoordinateRegion region; MKCoordinateSpan span; span.latitudeDelta=0.2; span.longitudeDelta=0.2; LocationClass *locationData=[[LocationClass alloc]init]; for (int k=0; k<contentArray.count; k++) { locationData=[contentArray objectAtIndex:k]; CLLocationCoordinate2D location; region.span = span; region.center = location; location.latitude =[locationData.latitude doubleValue]; location.longitude = [locationData.longitude doubleValue]; AnnView *mapPoint = [[AnnView alloc] initWithLocation:location]; mapPoint.title=[NSString stringWithFormat:@"%@ @",locationData.Title]; mapPoint.subtitle=[NSString stringWithFormat:@"%@ ",locationData.Subtitle]; [yourMapView addAnnotation:mapPoint]; mapPoint = nil; [yourMapView setRegion:region animated:YES]; [yourMapView regionThatFits:region]; } [self zoomToFitMapAnnotations:yourMapView]; 

然后编写如下代码的委托方法。

 - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { MKAnnotationView * annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"annot"]; if (!annotationView) { annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annot"] ; annotationView.canShowCallout = YES; } else { annotationView.annotation = annotation; } annotationView.image = [UIImage imageNamed:@"pinimage.png"]; return annotationView; } 

这里是从plist文件检索数据的示例,数据将存储到NSArray 。 您可以使用此数组显示注释。

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; NSString *fooPath = [documentsPath stringByAppendingPathComponent:@"yourPlistFile.plist"]; NSLog(fooPath); NSArray *contentArray = [NSArray arrayWithContentsOfFile:fooPath]; NSLog(@"%@",contentArray);