Reputation: 94
I want to place a pin whenever the screen is touched using MKMapView inside the method ViewDidLoad()
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;
}
How would I go about doing this? The Xamarindocs are specific about placing an image, but how do I place a pin? Isn't it built into MKMapView?
Upvotes: 0
Views: 378
Reputation: 89129
You add an 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);
Upvotes: 2