Friday, 25 September 2009

MonoTouch MapKit 102

UPDATE 27-Sep:MapKit 103 has the MKAnnotation working - DEVICE ONLY.

Thanks to Geoff and a bit of ObjC sample code I've figured out a little bit more of MapKit with MonoTouch. MKPlacemarks now appear (although I'm still working on MKAnnotation).

The main changes from MapKit 101 are:

FoundWithPlacemark
Now calls the *Object method added by Geoff.
_appd.mapView.AddAnnotationObject(placemark);

MapViewDelegate
Updated to pass the annotation into the constructor of MKPinAnnotationView and also set the properties for animation, color and showing the callout when clicked.
public override MKAnnotationView GetViewForAnnotation
(MKMapView mapView, NSObject annotation)
{
Console.WriteLine("get view MKAnnotation "+annotation);
var anv = mapView.DequeueReusableAnnotation("thislocation");
if (anv == null)
{
Console.WriteLine("creating new MKAnnotationView");
anv = new MKPinAnnotationView(annotation, "thislocation");
}
else
{
anv.Annotation = annotation;
}
anv.AnimatesDrop = true;
anv.PinColor = MKPinAnnotationColor.Green;
anv.CanShowCallout = true;
return anv;
}
Hopefully I can figure out the MKAnnotation issue too...

2 comments:

  1. Thanks for the update, Craig. Do you have an updated ZIP file with the full example?

    ReplyDelete
  2. Was going to wait until MKAnnotation works too - IMO MKPlacemark isn't quite as useful as MKAnnotation anyway. Will try to get something up this weekend.

    ReplyDelete