0

MKPolyline に問題があります。

このコードを追加しましたが、行が表示されません。http-request を使用して Web サーバーから座標を取得します。座標を double として保存し、注釈を表示します。

viewcontroller.h で

@property (nonatomic, retain) MKPolyline *routeLine; 
@property (nonatomic, retain) MKPolylineView *routeLineView; 

viewcontroller.m で

CLLocationCoordinate2D coordinateArray[7];
coordinateArray[0] = CLLocationCoordinate2DMake(theCoordinate0.latitude, theCoordinate0.longitude);
coordinateArray[1] = CLLocationCoordinate2DMake(theCoordinate1.latitude, theCoordinate1.longitude);
coordinateArray[2] = CLLocationCoordinate2DMake(theCoordinate2.latitude, theCoordinate2.longitude);
coordinateArray[3] = CLLocationCoordinate2DMake(theCoordinate3.latitude, theCoordinate3.longitude);
coordinateArray[4] = CLLocationCoordinate2DMake(theCoordinate4.latitude, theCoordinate4.longitude);
coordinateArray[5] = CLLocationCoordinate2DMake(theCoordinate5.latitude, theCoordinate5.longitude);
coordinateArray[6] = CLLocationCoordinate2DMake(theCoordinate6.latitude, theCoordinate6.longitude);

self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:7];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible

[self.mapView addOverlay:self.routeLine];

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
    if(overlay == self.routeLine)
    {
        if(nil == self.routeLineView)
        {
            self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine]autorelease];
            self.routeLineView.fillColor = [UIColor redColor];
            self.routeLineView.strokeColor = [UIColor redColor];
            self.routeLineView.lineWidth = 10;

        }

        return self.routeLineView;
    }

    return nil;
}
4

1 に答える 1

0

マップビューが画面上のマップビュー (Interface Builder の IBOutlet) に接続されていることを確認しましたか? 次に確認することは、デリゲートを設定したことです。関数にブレークポイントまたはデバッグ ステートメントを配置して、これを確認しviewForOverlayます。

PSそのコードを使用すると、1行しか描画できなくなります。それは依存してself.routeLineおりself.routeLineView、あなたはそれらのそれぞれを1つしか持っていません。

于 2013-03-30T07:06:36.193 に答える