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

Displaying maps


In this recipe, we will learn how to display maps in our app.

Getting ready

Create a new Single View Application in Xamarin Studio and name it MapDisplayApp.

How to do it...

Perform the following steps to display maps in the app:

  1. Add MKMapView on the controller. The following screenshot shows the symbol for MKMapView in Xcode's object library:

  2. Add the following using directives in the MapDisplayAppViewController.cs file:

    using MonoTouch.MapKit;
    using MonoTouch.CoreLocation;
  3. Enter the following code in the MapDisplayAppViewController class:

    public override void ViewDidLoad ()
    {
      base.ViewDidLoad ();
      this.mapView.ShowsUserLocation = true;
      this.mapView.RegionChanged += this.MapView_RegionChanged;
    }
    private void MapView_RegionChanged (object sender, MKMapViewChangeEventArgs e)
    {
      if (this.mapView.UserLocation.Location != null)
      {
        CLLocationCoordinate2D mapCoordinate = this.mapView.UserLocation.Location.Coordinate;
        Console.WriteLine("Current coordinates: LAT: {0}, LON: ...