放置一个Pin MKMapView

时间:2014-05-29 21:33:33

标签: xamarin.ios xamarin

我想在方法ViewDidLoad()

中使用MKMapView触摸屏幕时放置一个引脚
public override void ViewDidLoad ()
{
        base.ViewDidLoad ();

        // Perform any additional setup after loading the view, typically from a nib.
        mapView.ShowsUserLocation = true;
        MKUserLocation currentLocation = mapView.UserLocation;
}

我该怎么做呢? Xamarindocs专门用于放置图像,但如何放置图钉?它不是内置在MKMapView中吗?

1 个答案:

答案 0 :(得分:2)

您添加MKAnnotation to the Map

class BasicMapAnnotation : MKAnnotation{
    public override CLLocationCoordinate2D Coordinate {get;set;}
    string title, subtitle;
    public override string Title { get{ return title; }}
    public override string Subtitle { get{ return subtitle; }}
    public BasicMapAnnotation (CLLocationCoordinate2D coordinate, string title, string subtitle) {
        this.Coordinate = coordinate;
        this.title = title;
        this.subtitle = subtitle;
    }
}

var annotation = new BasicMapAnnotation (new CLLocationCoordinate2D(48.857,2.351), "Paris", "City of Light");
mapView.AddAnnotation(annotation);