Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding map annotations


In this recipe, we will discuss annotating a map to provide a variety of information to the user.

Getting ready

Create a new Single View Application in Xamarin Studio and name it MapAnnotateApp. Add MKMapView and a button on the view of the controller.

How to do it...

Perform the following steps to add annotations to a map:

  1. Add the MonoTouch.MapKit and MonoTouch.CoreLocation namespaces in the MapAnnotateAppViewController.cs file.

  2. Add the IMKMapViewDelegate interface to the MapAnnotateAppViewController class declaration using the following code:

    public partial class MapAnnotateAppViewController : UIViewController, IMKMapViewDelegate
  3. 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...