In the updated code which creates an MKPolygon
, the coordinates in the coords
array are backwards. For example, this line:
coords[0] = CLLocationCoordinate2DMake(
(region.center.longitude - 0.5*region.span.longitudeDelta),
(region.center.latitude + 0.5*region.span.latitudeDelta));
should be:
coords[0] = CLLocationCoordinate2DMake(
(region.center.latitude + 0.5*region.span.latitudeDelta,
(region.center.longitude - 0.5*region.span.longitudeDelta));
In the CLLocationCoordinate2DMake
function, the first parameter is latitude, then longitude.
Because the coordinates are backwards, they may either be completely invalid or in the wrong location.
The rendererForOverlay
delegate method will only get called if the overlay's boundingMapRect
(which MKPolygon
will automatically define based on the given coordinates) is in the currently displayed area of the map. But if the coordinates are invalid or in the wrong location, the boundingMapRect
will be invalid as well.
By the way, in the original code which used
CustomMapOverlay
, there were at least these two issues:
- The
initWithModel
method doesn't call[super init]
(assuming it's anNSObject
subclass). - The
boundingMapRect
is not calculated correctly. TheMKMapRectMake
function takesMKMapPoint
values but the code is passing latitude and longitude in degrees. AnMKMapPoint
is not the same as aCLLocationCoordinate2D
. You can convert aCLLocationCoordinate2D
to anMKMapPoint
using theMKMapPointForCoordinate
function. See MKMapPointForCoordinate returning invalid coordinates and Map Coordinate Systems in the documentation for some more info.