Ios 无法绘制MKPolylineView交叉经度+/-180

Ios 无法绘制MKPolylineView交叉经度+/-180,ios,mapkit,mkoverlay,Ios,Mapkit,Mkoverlay,在MKMapView上绘制MKPolylineView时遇到问题。这条线代表了一次环球旅行,从纽约开始到结束,一直向东旅行。旅程的一条腿,从日本到旧金山,穿越太平洋,因此经度+/- 180。MKPolylineView确实连接了这两个点,但它的移动方向错误。也就是说,这条线从日本向西旅行回旧金山,而不是东穿过太平洋。我看不到任何选项允许我指定线段连接两点的方向 简单地说,MKMapView似乎不理解世界是圆的。有没有一条路能像我预期的那样划定路线,从日本东到旧金山? 我有一个清晰显示问题的屏幕截

在MKMapView上绘制MKPolylineView时遇到问题。这条线代表了一次环球旅行,从纽约开始到结束,一直向东旅行。旅程的一条腿,从日本到旧金山,穿越太平洋,因此经度+/- 180。MKPolylineView确实连接了这两个点,但它的移动方向错误。也就是说,这条线从日本向西旅行回旧金山,而不是东穿过太平洋。我看不到任何选项允许我指定线段连接两点的方向

简单地说,MKMapView似乎不理解世界是圆的。有没有一条路能像我预期的那样划定路线,从日本东到旧金山? 我有一个清晰显示问题的屏幕截图:

这似乎是MKMapView的一个限制

解决方法是将+/-180交叉口分为“东”和“西”两部分

对于环球旅行(finish==start),可以将交叉点的“west”部分放在多段线的前面。
例如:

CLLocationCoordinate2D newYorkCoord = CLLocationCoordinate2DMake(40.7141667, -74.0063889);
CLLocationCoordinate2D londonCoord = CLLocationCoordinate2DMake(51.5, -0.116667);
CLLocationCoordinate2D japanCoord = CLLocationCoordinate2DMake(36, 138);
CLLocationCoordinate2D sanFranciscoCoord = CLLocationCoordinate2DMake(37.775, -122.4183333);

CLLocationCoordinate2D japanToSFMidpointEast;
//use average calc as crude way to find midpoint...
japanToSFMidpointEast.latitude = (japanCoord.latitude + sanFranciscoCoord.latitude)/2.0;
japanToSFMidpointEast.longitude = 180;

CLLocationCoordinate2D japanToSFMidpointWest;
japanToSFMidpointWest.latitude = japanToSFMidpointEast.latitude;
japanToSFMidpointWest.longitude = -180;

int pointsCount = 6;
CLLocationCoordinate2D *points = malloc(pointsCount * sizeof(CLLocationCoordinate2D));
points[0] = japanToSFMidpointWest;
points[1] = sanFranciscoCoord;
points[2] = newYorkCoord;
points[3] = londonCoord;
points[4] = japanCoord;
points[5] = japanToSFMidpointEast;
MKPolyline *polyline = [MKPolyline polylineWithCoordinates:points count:pointsCount];
[mapView addOverlay:polyline];
free(points);
points = NULL;

如果旅行不是环游世界(finish!=start),则必须使用两条多段线。
这个例子从日本到旧金山:

CLLocationCoordinate2D japanCoord = CLLocationCoordinate2DMake(36, 138);
CLLocationCoordinate2D sanFranciscoCoord = CLLocationCoordinate2DMake(37.775, -122.4183333);

CLLocationCoordinate2D japanToSFMidpointEast;
japanToSFMidpointEast.latitude = (japanCoord.latitude + sanFranciscoCoord.latitude)/2.0;
japanToSFMidpointEast.longitude = 180;

CLLocationCoordinate2D japanToSFMidpointWest;
japanToSFMidpointWest.latitude = japanToSFMidpointEast.latitude;
japanToSFMidpointWest.longitude = -180;

int eastPointsCount = 2;
CLLocationCoordinate2D *eastPoints = malloc(eastPointsCount * sizeof(CLLocationCoordinate2D));
eastPoints[0] = japanCoord;
eastPoints[1] = japanToSFMidpointEast;
MKPolyline *eastPolyline = [MKPolyline polylineWithCoordinates:eastPoints count:eastPointsCount];
[mapView addOverlay:eastPolyline];
free(eastPoints);
eastPoints = NULL;

int westPointsCount = 2;
CLLocationCoordinate2D *westPoints = malloc(westPointsCount * sizeof(CLLocationCoordinate2D));
westPoints[0] = japanToSFMidpointWest;
westPoints[1] = sanFranciscoCoord;
MKPolyline *westPolyline = [MKPolyline polylineWithCoordinates:westPoints count:westPointsCount];
[mapView addOverlay:westPolyline];
free(westPoints);
westPoints = NULL;

谢谢我正在考虑类似的解决方案,但希望MapKit中可能有一些我错过的功能。