내 앱은 HomeVC의 MKOverlayRenderer로 MKMapView의 MKPolyline 라우팅 경로로 GPS 이동을 추적하고 데이터를 저장 한 다음 나중에 몇 개의 VC가 저장된 경로로 DisplayVC에 표시합니다. 데이터가 두 번째 VC의 원래 데이터와 동일하다는 것을 확인할 수 있으며지도가 표시 될 때 적절한 routeBounds가 사용되지만 두 번째 VC에서는 OverlayRenderer가 호출되지 않습니다. 왜 안돼? 나는 대의원 문제를 생각하고있다. 그러나 나는 틀린 것을 발견 할 수 없다.동일한 MKOverlayView 대리인이 하나의 UIView에서 호출되었지만 다른 MView에서는 호출되지 않았습니다. 누락 된 것이 무엇입니까?
두 homeVC.h
@interface homeVC : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate> {
및 displayVC.h이 이름을 제외하고는 동일합니다까지 동일하게 설정되어
@interface displayVC : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate> {
CLLocationManager *locationManager;
// the data representing the route points
MKPolyline* _routePath;
// the view we create for the line on the map
MKPolylineView* _routePathVw;
// the rect that bounds the loaded points
MKMapRect _routeBounds;
}
@property (nonatomic, weak) IBOutlet MKMapView *mapView;
@end
그리고 homeVC.m 및 displayVC.m 모두 :
- (void)viewDidLoad {
[super viewDidLoad];
// Add the Map
[_mapView setDelegate:self];
_mapView.mapType = MKMapTypeStandard;
}
많은 유용한 코드가 있습니다. 그런 다음
-(void) buildRoute {
CLLocationCoordinate2D thisCoord;
int i = [arrayLa count] - 1; // keep growing the array size
MKMapPoint *tmpArr = realloc(pointArr, sizeof(CLLocationCoordinate2D)*(arrayLa.count));
pointArr = tmpArr;
thisCoord.latitude = [[arrayLa objectAtIndex:i] floatValue];
thisCoord.longitude = [[arrayLo objectAtIndex:i] floatValue];
MKMapPoint point = MKMapPointForCoordinate(thisCoord);
pointArr[i] = point;
// Reset Map View Boundaries
if(point.x > ne_Pt.x - 500) ne_Pt.x = point.x + 1000;
if(point.y > ne_Pt.y - 500) ne_Pt.y = point.y + 1000;
if(point.x < sw_Pt.x + 500) sw_Pt.x = point.x - 1000;
if(point.y < sw_Pt.y + 500) sw_Pt.y = point.y - 1000;
// create the polyline based on the C-array of map Points
_routePath = [MKPolyline polylineWithPoints:pointArr count:arrayLa.count];
_routeBounds = MKMapRectMake(sw_Pt.x, sw_Pt.y, ne_Pt.x-sw_Pt.x, ne_Pt.y-sw_Pt.y);
// add the routePath overlay to the map, if it isn't empty
if (recState == REC && _routePath != nil) {
// zoom in on the route with the fresh bounding box, routeBounds
[self zoomInOnRoute];
[_mapView addOverlay:_routePath];
}
}
-(void) zoomInOnRoute {
[_mapView setVisibleMapRect:_routeBounds];
}
#pragma mark MKMapViewDelegate
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolyline *route = overlay;
MKPolylineRenderer *routeRenderer = [[MKPolylineRenderer alloc] initWithPolyline:route];
routeRenderer.lineWidth = 3;
routeRenderer.strokeColor = [UIColor redColor];
return routeRenderer;
}
else return nil;
}
누구든지 내 문제를 해결할 수 있습니까? 감사합니다.
감사합니다. 실행되지 않은 if() 전에 NSLog가있었습니다. –
답변에 조금 더 추가되었습니다. 아마도 polyLine에 포인트를 보내지 않았습니까? 희망이 도움이됩니다. – greentor
고마워, 다시,하지만 모든 포인트가 올바르게 경로에 있다고 확신합니다. –