为什么不调用MapKit的rendererForOverlay?

时间:2014-09-29 15:17:04

标签: objective-c ios7 delegates mapkit xcode6

我正在尝试使用纬度和经度初始化CLLocation。然后将其添加到名为trackPointArray的NSMutableArray中。

在循环中执行此操作后,CLLocation

中有currLocationCLLocation *currLocation = [[CLLocation alloc] initWithLatitude:lastlang longitude:lastlong]; [trackPointArray addObject:currLocation];
CLLocationCoordinate2D

添加到该数组后,我创建了一个NSInteger numberOfSteps =trackPointArray.count; CLLocationCoordinate2D coordinates[numberOfSteps]; for(NSInteger index=0;index<numberOfSteps;index++) { CLLocation *location = [trackPointArray objectAtIndex:index]; CLLocationCoordinate2D coordinate2 = location.coordinate; coordinates[index] = coordinate2; }

routeLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
[self.mapView addOverlay:routeLine];

最后我打电话给他:

rendererForOverlay

此功能为- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay { if (![overlay isKindOfClass:[MKPolygon class]]) { return nil; } MKPolygon *polygon = (MKPolygon *)overlay; MKPolygonRenderer *renderer = [[MKPolygonRenderer alloc] initWithPolygon:polygon]; renderer.fillColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4]; return renderer; }

rendererForOverlay
  1. 我调试了我的项目,但没有调用viewDidLoad()
  2. 我在MapView self.mapView.delegate = self;
  3. 后面有这行代码
  4. 我有一点以上
  5. 以下是头文件中我的委托的定义:

    UIViewController&lt; MKMapViewDelegate,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,MKOverlay&gt;

  6. 5。@property (weak, nonatomic) IBOutlet MKMapView *mapView; =

    NSMutableArray *trackPointArray;
    MKMapRect routeRect;
    MKPolylineView* routeLineView;
    MKPolyline* routeLine;
    
    1. 我在模拟器上尝试这个。而模拟器正在带来l
    2. 以下是我的变量的定义:

      -(MKOverlayView *) mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
      {
          MKPolylineView *polylineview = [[MKPolylineView alloc] initWithPolyline:overlay];
          polylineview.strokeColor = [UIColor redColor];
          polylineview.lineWidth = 5.0;
          return polylineview;
      }
      

      我也使用过这个旧版本,但它也没有被调用:

      - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
      {
          if ([overlay isKindOfClass:[MKPolyline class]]) {
              MKPolyline *route = overlay;
              MKPolylineRenderer *routeRenderer = [[MKPolylineRenderer alloc] initWithPolyline:route];
              routeRenderer.strokeColor = [UIColor blueColor];
              return routeRenderer;
          }
          else return nil;
      }
      

      如果有人能帮助我,我感激不尽。

      感谢Anna的评论,我认为这可以解决这个问题:

      {{1}}

0 个答案:

没有答案