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