2012-08-28 6 views

답변

0

먼저 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; 
} 
1

여기 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);