1

我曾经MKMapView显示正常工作的地图和当前用户位置。现在我想在用户移动时绘制一条折线,但它不起作用我尝试了以下代码:

for(int i = 0; i < [longarray count]; i++)
{
    NSNumber *latt=[latarray objectAtIndex:i];
    NSNumber *lonn=[longarray objectAtIndex:i];
    sklat =[[NSString stringWithFormat:@"%@",latt]doubleValue];
    sklongi =[[NSString stringWithFormat:@"%@",lonn]doubleValue];
    CLLocationCoordinate2D coordinate1 = CLLocationCoordinate2DMake(sklat,sklongi);
    // break the string down even further to latitude and longitude fields.
    MKMapPoint point = MKMapPointForCoordinate(coordinate1);
    // if it is the first point, just use them, since we have nothing to compare to yet.
    pointsArray[i] = point;
}
self.routeLine = [MKPolyline polylineWithPoints:pointsArray count:[latarray count]];
free(pointsArray);
[mapview addOverlay:self.routeLine];

然后我使用覆盖功能作为

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
    MKOverlayView* overlayView = nil;
    if(overlay == self.routeLine)
    {
        routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine] ;
        routeLineView.fillColor = [UIColor colorWithRed:0.000 green:5.100 blue:0.100  alpha:1];
        routeLineView.strokeColor = [UIColor colorWithRed:0.000 green:5.100 blue:0.100 alpha:1];
        routeLineView.lineWidth = 4;
        overlayView = routeLineView;
    }
    return overlayView;
}
4

0 回答 0