0

トラックまたはルートを地図上のオーバーレイとして表示する方法を示すサンプル コードを含むチュートリアルをインターネットで検索しようとしています。いくつかのチュートリアルを見つけましたが、それらは円やその他の形状を表示するためのものです。ポイントごとのトラックを表示したかったのです。

誰かが私に良いチュートリアルへのリンクを教えてくれますか、誰かが私を正しい方向に向けることができますか?

どんな助けでも大歓迎です。

乾杯

4

3 に答える 3

1
MapView* mapView = [[[MapView alloc] initWithFrame:
                         CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)] autorelease];

[self.view addSubview:mapView];

Place* home = [[[Place alloc] init] autorelease];
home.name = @"Home";
home.description = @"Sweet home";
home.latitude = 29.860323999999990000;
home.longitude =77.893305000000050000;

Place* office = [[[Place alloc] init] autorelease];
office.name = @"Office";
office.description = @"Bad office";
office.latitude = 28.644251400000000000;
office.longitude = 77.121190500000010000;

[mapView showRouteFrom:home to:office];

これをios 7.0で使用します

于 2014-01-29T10:27:14.397 に答える
1

MKPolyline を使用してみてください。ルートに沿った各ターン ポイントの座標を使用して CLLocation の配列を作成します。その配列で MKPolyline オブジェクトを初期化します。これにより、指定した各ポイント間に実線が描画されます。次に、ラインを分割する必要があるほどポイントが離れている場合は、ラインの dashPattern と dashPhase を調整できます。

ポイントと呼ばれる緯度経度ポイントの NSMutableArray から始めました。

NSMutableArray *currentPoint;
int count = [points count];
double lat, long;

CLLocationCoordinate2D unitPath[count];
for (NSInteger index = 0; index < count; index++)
{
    currentPoint = [points objectAtIndex:index];

    Lat = [[currentPoint objectAtIndex:ORDER_TARGLAT] doubleValue];
    Long = [[currentPoint objectAtIndex:ORDER_TARGLONG] doubleValue];
    CLLocation *pathPoint = [[CLLocation alloc] initWithLatitude:Lat longitude:Long];
    unitPath[index] = pathPoint.coordinate;
}

MKPolyline *routeLine = [MKPolyline polylineWithCoordinates:unitPath count:count];

routeLine.title = _title;
routeLine.subtitle = [[NSString alloc] initWithFormat:@"%d",ID];
routeLine.strokeColor = [UIColor whiteColor];
routeLine.fillColor = [UIColor whiteColor];
NSNumber *lineGapSize = [NSNumber numberWithInteger:10];
routeLine.dashPattern = [NSArray arrayWithObjects:lineGapSize,lineGapSize,nil];
routeLine.dashPhase = lineDashPhase;
routeLine.lineWidth = 4; 

[mapView addOverlay:routeLine]

PS ORDER_TARGLAT と ORDER_TARGLONG は、配列内の項目の位置を指定する列挙型の一部にすぎません。コードに応じて置き換えてください。

于 2012-12-02T05:16:18.167 に答える