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 overlays


In this recipe, we will learn how to add a red circle overlay over a point on the map.

Getting ready

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

How to do it...

Perform the following steps to add overlays on the map:

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

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

    public partial class MapOverlayAppViewController : UIViewController, IMKMapViewDelegate
  3. Add the following code in the ViewDidLoad method:

    this.mapView.ShowsUserLocation = true;
    this.mapView.WeakDelegate = this;
    this.btnAddOverlay.TouchUpInside += (sender, e) => {
      CLLocationCoordinate2D mapCoordinate = 
        this.mapView.UserLocation.Coordinate;
      this.mapView.SetRegion(MKCoordinateRegion.FromDistance(mapCoordinate, 1000, 1000), true);
      MKCircle circle = 
        MKCircle.Circle(mapCoordinate...