質問

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