문제

In MKMapView, I created a polygon using these points:

1- lat = 0.0; long = -170;
2- lat = 0.0; long =  170;
3- lat = 10; long = 180;

The first two points are only 20 degrees apart, but the MKMapView draws it in the other direction around the world (which is 170 + 170 = 340 degrees apart).

Is there any fix to that?

도움이 되었습니까?

해결책

I'm surprised you're having issues with this in iOS 7, as they handle spanning the meridian better than prior versions. In iOS 7, the following:

CLLocationCoordinate2D coordinates[3];
coordinates[0] = CLLocationCoordinate2DMake(0, -170);
coordinates[1] = CLLocationCoordinate2DMake(0, 170);
coordinates[2] = CLLocationCoordinate2DMake(10, 180);
MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coordinates count:3];
[self.mapView addOverlay:polygon];

produces (assuming you implement the typical rendererForOverlay):

enter image description here

Doing this in prior iOS versions, it may not handle this properly, but in iOS 7, you should be fine. If you are still having issues, perhaps you can share how you've generated this polygon.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top