Use MKOverlay and MKOverlayRenderer
MKOverlay
Write your own overlay class (for example, MapOverlay
) confirm to MKOverlay
, synthesize coordinate
and boundingMapRect
, so that we can assign value to them while initializing it.
Note that the type of coordinate
is CLLocationCoordinate2D
with latitude
and longitude
, while boundingMapRect
is MKMapRect
. And we need to use MKMapPointForCoordinate
method to convert a CLLocationCoordinate2D
type data to MKMapPoint
type data. If we assign the CLLocationCoordinate2D
data directly to boundingMapRect
, the overlay will be too small to draw, and the mapView:rendererForOverlay:
method will not be called at all. It is very hard for debugging.