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

Geocoding


In this recipe, we will learn how to provide information about an address, city, or country based on location coordinates.

Getting ready

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

How to do it...

Perform the following steps:

  1. Add an MKMapView on the top half of the view of MainController, a label, and a button on the bottom half.

  2. Add the MonoTouch.MapKit and MonoTouch.CoreLocation namespaces in the GeocodingAppViewController.cs file.

  3. Enter the following ViewDidLoad method in the class:

    private CLGeocoder geocoder;
    public override void ViewDidLoad () {
      base.ViewDidLoad ();
      this.mapView.ShowsUserLocation = true;
      this.btnGeocode.TouchUpInside += async (sender, e) => {
        this.lblOutput.Text = "Reverse geocoding location...";
        this.btnGeocode.Enabled = false;
        CLLocation currentLocation = 
          this.mapView.UserLocation.Location;
        this.mapView.SetRegion(MKCoordinateRegion.FromDistance(currentLocation.Coordinate, 1000, 1000), true);
    ...