我对Xcode非常陌生,在使用polyline跟踪用户路径方面面临问题。
我得到了正确的位置。我能正确地添加引脚。但是,我的polyline方法从未被调用过。
下面是我的密码。
在头文件中。
@interface Tracker : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
{
MKMapView *mapView;
//other declarations
}在实现文件中,我有以下代码。我调用,drawPolyline方法内部的didUpdateLocations方法,这是正确的调用。
- (void) drawPolyline:(NSArray *)locations
{
NSInteger numberOfLocations = [locations count];
if (numberOfLocations > 1)
{
CLLocationCoordinate2D *locationCoordinate2DArray = malloc(numberOfLocations * sizeof(CLLocationCoordinate2D));
for (int i = 0; i < numberOfLocations; i++)
{
CLLocation* current = [locations objectAtIndex:i];
locationCoordinate2DArray[i] = current.coordinate;
}
self.polyline = [MKPolyline polylineWithCoordinates:locationCoordinate2DArray count:numberOfLocations];
free(locationCoordinate2DArray);
[mapView addOverlay:self.polyline];
[mapView setNeedsDisplay];
}
}
- (MKOverlayView*)mapView:(MKMapView*)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKPolylineView* polyLineView = [[MKPolylineView alloc] initWithPolyline:self.polyline];
polyLineView.strokeColor = [UIColor blueColor];
polyLineView.lineWidth = 2;
return polyLineView;
}你的帮助是非常感谢的。提前谢谢。
发布于 2013-09-01 23:21:38
mapView:viewForOverlay:是一个委托方法,因此您需要在某个地方设置mapview的委托。否则,将永远不会调用委托方法。
[mapView setDelegate:self];https://stackoverflow.com/questions/18563369
复制相似问题