Displaying a triangle as MKPolygon on MKMap

323 Views Asked by At

I am trying to display a triangle as an MKPolygon on a map. So far I have not used swift very much and might be missing some very obvious point.

After creating the overlay and calling map.addOverlay() to my surprise neither mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) nor mapView(mapView: MKMapView!, viewForOverlay overlay: MKOverlay!) get called. Am I missing something here? PS: For the sake of simplicity I omitted any error checks.

Thanks for your help.

My implementation is below:

func addOverlay()
{
    var coordinates = [CLLocationCoordinate2DMake(47.0, 8.0),CLLocationCoordinate2DMake(47.5, 8.5),CLLocationCoordinate2DMake(47.5, 7.5)]
    let overlay = MKPolygon(coordinates: &coordinates, count: coordinates.count)

    map.addOverlay(overlay)  
}

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
    var oR = MKPolygonRenderer(overlay: overlay)
    oR.strokeColor = UIColor.blackColor()
    oR.fillColor = UIColor.greenColor()

    return oR
}

func mapView(mapView: MKMapView!, viewForOverlay overlay: MKOverlay!) -> MKOverlayView! {
    var pV  = MKPolygonView(overlay: overlay)

    return pV
}
0

There are 0 best solutions below