2
간단한 iPhone 앱의지도 오버레이를 만들려고합니다. 문제는 앱이 오류를 준수하지 않더라도 폴리 라인이지도에 표시되지 않는다는 것입니다. 콘솔은 [overlay lastObject]가 실제로 MKPolyline이라는 것을 말합니다. 누군가 내가 어쩌면 내가 뭘 잘못하고 있는지 볼 수 있을까 ... 나는 아이폰 앱 개발에 새로운가요?MKMapView 및 addOverlay - kml에서 오버레이 구문 분석
여기 내지도보기 컨트롤러 내 관련 코드입니다 :
- (void)viewDidLoad {
[super viewDidLoad];
CGRect mapFrame = CGRectMake(0.0f, 31.0f, 320.0f, 370.0f);
mapView = [[MKMapView alloc] initWithFrame:mapFrame];
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=.02;
span.longitudeDelta=.02;
CLLocationCoordinate2D location;
location.latitude = 29.43421;
location.longitude = -98.48436;
region.span=span;
region.center=location;
NSURL *url = [NSURL URLWithString:@"They asked me not to post this... It is a valid KML file though"];
kml = [[KMLParser parseKMLAtURL:url] retain];
// Add all of the MKOverlay objects parsed from the KML file to the map.
NSArray *overlay = [kml overlays];
NSLog(@"TEST: %@",[overlay lastObject]);
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[mapView addOverlay:[overlay lastObject]];
[self.view insertSubview:mapView atIndex:0];
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bkgd.png"]];
self.view.backgroundColor = background;
[background release];
[url release];
}
#pragma mark-
#pragma mark MKMapViewDelegate
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKPolylineView *line = [[[MKPolylineView alloc] initWithPolyline:overlay] autorelease];
line.strokeColor = [UIColor blueColor];
line.lineWidth = 5;
return line;
}
고맙습니다! 훌륭하게 작동합니다. – Katherine