我有以下代码:
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
地图中心点的坐标。使用这两组坐标,我创建了一个数组,将这两组坐标CLLocationCoordinate2D coordinates[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 相对应的所有四条线。