次のコードがあります。
MKMapRect mRect = self.mapView.visibleMapRect;
MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMaxY(mRect)/2);
MKMapPoint northMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect)/2, 0);
MKMapPoint southMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect)/2, MKMapRectGetMaxY(mRect));
MKMapPoint westMapPoint = MKMapPointMake(0, MKMapRectGetMaxY(mRect)/2);
CLLocationCoordinate2D
これらをwithに変換していMKCoordinateForMapPoint
ます。例えば:
CLLocationCoordinate2D northCoords = MKCoordinateForMapPoint(northMapPoint);
とともに、地図の中心にある点の座標northCoords
を持っています。centerCoords
これら 2 つの座標セットを使用して、これら 2 つのセットを追加する配列を作成しCLLocationCoordinate2D coordinates[2]
ます...
次に、次のコードを使用して 2 つの座標間に線を引きます。
MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:2];
[_mapView addOverlay:polyLine];
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.strokeColor = [UIColor redColor];
polylineView.lineWidth = 5.0;
return polylineView;
}
問題:
ポリライン オーバーレイの開始点 (マップの中心) は、常に中心から始まります。ただし、線のもう一方の端 (北/南/東/西) は、あるべき場所を正しく指していません。下の画像では、上の 4 つの MKMapPoint に対応する 4 つの線すべてを描画しています。