无法绘制mkpolyline

时间:2012-10-04 04:06:29

标签: ios xcode gps mkmapview

我使用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;
}

0 个答案:

没有答案
相关问题