iOSアプリケーションを実装していて、マップ上のいくつかの指定された座標の間にポリラインを描画したいと思います。
コードを書いて、無限遠点に到達するポイントからポリラインを描画しました。言い換えれば、線の始点は私の与えられた緯度と経度の点から始まりますが、線の終点は無限であり、他の点ではありません。
これは私のコードです...
NSMutableArray
と呼ばれる場所に座標を入力しましたrouteLatitudes
。配列セルは、緯度用と経度用に1つずつ埋められています。
MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * [routeLatitudes count]);
for(int idx = 0; idx < [routeLatitudes count]; idx=idx+2)
{
CLLocationCoordinate2D workingCoordinate;
workingCoordinate.latitude=[[routeLatitudes objectAtIndex:idx] doubleValue];
workingCoordinate.longitude=[[routeLatitudes objectAtIndex:idx+1] doubleValue];
MKMapPoint point = MKMapPointForCoordinate(workingCoordinate);
pointArr[idx] = point;
}
// create the polyline based on the array of points.
routeLine = [MKPolyline polylineWithPoints:pointArr count:[routeLatitudes count]];
[mapView addOverlay:self.routeLine];
free(pointArr);
とオーバーレイデリゲート
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
if(overlay == routeLine)
{
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
self.routeLineView.fillColor = [UIColor colorWithRed:51 green:51 blue:255 alpha:1];
self.routeLineView.strokeColor = [UIColor colorWithRed:204 green:0 blue:0 alpha:1];
self.routeLineView.lineWidth = 3;
overlayView = routeLineView;
}
return overlayView;
}
そのため、マップ上のポイント間に線を引く必要があります。行の先頭は最初にドロップされたピンであり、最後は最後にドロップされたピンにあります。