我正在尝试使用纬度和经度初始化CLLocation。然后将其添加到名为trackPointArray
的NSMutableArray中。
在循环中执行此操作后,CLLocation
currLocation
个CLLocation *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
viewDidLoad()
MapView
self.mapView.delegate = self; 以下是头文件中我的委托的定义:
UIViewController&lt; MKMapViewDelegate,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,MKOverlay&gt;
5。@property (weak, nonatomic) IBOutlet MKMapView *mapView;
=
NSMutableArray *trackPointArray;
MKMapRect routeRect;
MKPolylineView* routeLineView;
MKPolyline* routeLine;
以下是我的变量的定义:
-(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}}