[MonoTouch] problem adding map overlay

Jason Awbrey jason at awbrey.net
Wed Oct 5 16:54:57 EDT 2011


I'm having some trouble adding an overlay to a map.  It's an iPad app with a
SplitViewController containing a TableView and a MapView.  It doesn't seem
like the mapview's delegate is getting called when I add the overlay.  I'm
not using IB - everything is in code.

In my row selected, I set the map's center (that part works) then add a
Polygon overlay.  The coordinates for the polygon come from the TableSource;

        public override void RowSelected (UITableView tableView,
MonoTouch.Foundation.NSIndexPath indexPath)
        {

            MKPolygon poly = _data [indexPath.Row].GetPolygon ();
            _map.AddOverlay (poly);

            CLLocationCoordinate2D xy = new CLLocationCoordinate2D (_data
[indexPath.Row].GetPolygon ().Points [0].X, _data [indexPath.Row].GetPolygon
().Points [0].Y);
            _map.SetCenterCoordinate (xy, true);
            _map.Region = new MKCoordinateRegion (xy, new MKCoordinateSpan
(0.1, 0.1));

        }

my map delegate - the GetViewForOverlay is never being called

    public class MapDelegate : MKMapViewDelegate
    {
        public MapDelegate ()
        {
            Console.WriteLine ("MapDelegate created");
        }

        public override MKOverlayView GetViewForOverlay (MKMapView mapView,
NSObject overlay)
        {

            Console.WriteLine ("GetViewForOverlay");

            MKOverlayView overlayView = null;

            if (overlay is MKPolygon) {
                MKPolygon poly = overlay as MKPolygon;
                var polyView = new MKPolygonView (poly);
                polyView.FillColor = UIColor.Red;
                polyView.Alpha = 0.7f;
                overlayView = polyView;
            }

            return overlayView;
        }
    }

Am I missing something extremely obvious?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20111005/0c84e434/attachment.html 


More information about the MonoTouch mailing list