k1komans
k1komans

Reputation: 299

MonoTouch Multiple Mapkit CLLocationCoordinate2D with Custom PIN Image

Hello my main issue is how to use MKAnnotationView to set a custom pin image for all my coordinate points.

For reference, I've went ahead and hardcoded values that I will normally be calling down from a json webservice call. Heres an example of a hardcoded trails:

CLLocationCoordinate2D[] trail1 = new CLLocationCoordinate2D[]{
new CLLocationCoordinate2D(10.74812, -97.330277),
new CLLocationCoordinate2D(10.74501, -97.350277),
new CLLocationCoordinate2D(10.74912, -97.340277),
};

CLLocationCoordinate2D[] trail2 = new CLLocationCoordinate2D[]{
new CLLocationCoordinate2D(10.84812, -97.331277),
new CLLocationCoordinate2D(10.94501, -97.352277),
new CLLocationCoordinate2D(10.14912, -97.343277),
new CLLocationCoordinate2D(10.12912, -97.313277),    
};

mapview.AddAnnotation (new SampleMapAnnotation (trail1));

Right now I am using MKAnnotation but realized I need to use the MKAnnotationView for custom image pins.

public class SampleMapAnnotation : MKAnnotation 
{
string _title;

public SampleMapAnnotation (CLLocationCoordinate2D coordinate)
{
Coordinate = coordinate;
_title = "Sample";
}

public override CLLocationCoordinate2D Coordinate { get; set; }

public override string Title
        {
            get {
                return _title;
        }
    }
}

Upvotes: 2

Views: 996

Answers (1)

poupou
poupou

Reputation: 43553

Have a look at the MapCallout sample from Xamarin. This is a C# port from the Objective-C sample by Apple. It will show you how to create image-based annotations and show them on a map.

Upvotes: 2

Related Questions