지도 주석을 사용하고 싶습니다. plist 목록에 데이터가 있고, 지도에 주석을 사용하여 데이터를 표시하고 싶습니다. 데모 예제 MapCallsout을 가지고 있지만지도에 plist를 읽으려면 이 있습니까?데모 예제 plist를 사용한 다중 맵 주석?
0
A
답변
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);
관련 문제
- 1. Carrierwave 및 ffmpeg gem을 사용한 예제/데모 응용 프로그램
- 2. 큰 데이터 데모/예제 애플리케이션이 있습니까?
- 3. 주석 파서의 예제 코드
- 4. TabBarController를 사용한 SimpleDrillDown 예제
- 5. OpenGL을 사용한 2D 예제
- 6. discreteMapper를 사용한 예제
- 7. Symfony2를 사용한 사용자 정의 주석의 간단한 예제
- 8. 티타늄 - 다중 주석 만들기
- 9. Mapkit 다중 주석
- 10. C에서 다중 포크 예제
- 11. Maven을 사용한 예제 코드 아카이브
- 12. aop을 사용한 Spring.net 로깅 예제
- 13. Guice 서블릿을 사용한 간단한 예제
- 14. 다중 키 맵 (C++)
- 15. MATLAB의 Geoshow를 사용한 컬러 맵
- 16. UITapGestureRecognizer를 사용한 다중 탭
- 17. WSGI를 사용한 다중 프로세스
- 18. Bouncycastle을 사용한 다중 암호화
- 19. mvc3을 사용한 다중 조건
- 20. 다중 ViewModel을 사용한 하나의보기
- 21. GLUT를 사용한 다중 텍스처링
- 22. OpenSSL을 사용한 다중 연결
- 23. 다중 판별자를 사용한 상속?
- 24. 코드를 주석 처리하여 코드를 테스트하는 예제
- 25. 다중 값 다중 우선 순위 정렬 맵
- 26. XML 문서의 다중 언어 예제
- 27. 주석 JPA에서 엔티티가 아닌 클래스를 포함하는 맵
- 28. RavenDb에서 다중 맵/축소가 작동합니까?
- 29. Struts2의 다중 키 맵 액세스
- 30. 자바에서 얕은 복사 및 전체 복사본 데모 예제