【发布时间】:2013-09-01 22:00:45
【问题描述】:
我是 Xcode 的新手,在使用折线跟踪用户路径时遇到问题。
我正在正确获取位置。我能够正确添加引脚。但是,我的折线方法永远不会被调用。
下面是我的代码。
在头文件中...
@interface Tracker : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
{
MKMapView *mapView;
//other declarations
}
在实现文件中,我有以下代码。我在didUpdateLocations方法里面调用drawPolyline方法,调用正确。
- (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;
}
我们非常感谢您的帮助。提前致谢。
【问题讨论】:
标签: ios mkmapview mkpolyline