user3556225
user3556225

Reputation: 83

Drawing a polygon in MKMapView IOS 7 is not correct

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?

Upvotes: 2

Views: 2253

Answers (1)

Rob
Rob

Reputation: 437372

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.

Upvotes: 2

Related Questions