In this recipe, we will discuss annotating a map to provide a variety of information to the user.
Create a new Single View Application in Xamarin Studio and name it MapAnnotateApp
. Add MKMapView
and a button on the view of the controller.
Perform the following steps to add annotations to a map:
Add the
MonoTouch.MapKit
andMonoTouch.CoreLocation
namespaces in theMapAnnotateAppViewController.cs
file.Add the
IMKMapViewDelegate
interface to theMapAnnotateAppViewController
class declaration using the following code:public partial class MapAnnotateAppViewController : UIViewController, IMKMapViewDelegate
Add the following code in the
ViewDidLoad
method:this.mapView.ShowsUserLocation = true; this.mapView.WeakDelegate = this; this.btnAddPin.TouchUpInside += (sender, e) => { CLLocationCoordinate2D mapCoordinate = this.mapView.UserLocation.Coordinate; this.mapView.SetRegion(MKCoordinateRegion.FromDistance(mapCoordinate, 1000, 1000), true...