使用plist的任何演示示例多个地图注释? [英] Any demo example Multiple Map Annotation using plist?
本文介绍了使用plist的任何演示示例多个地图注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Map注释我有plist列表,其中我有数据,我想
使用注释在地图上显示数据。我有演示示例MapCallsout,但我有
来读取地图上的plist?
i want to use Map annotation i have plist list in which i have data and i want to show data on map using annotation. I have the demo example MapCallsout but i have to read plist on map?
推荐答案
首先获取所有位置Plist并将它们放入数组中。
First get All The Locations from Plist and put them into an Array.
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);
使用以下代码在地图上显示多个注释。
Use Below code for showing multiple annotations on your map.
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];
然后编写委托方法,如下面的代码。
Then Write the delegate Method Like Below Code.
- (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的任何演示示例多个地图注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文