Accessing GPS data on the IPhone with MonoTouch

A lot of .Net developers have probably heard about MonoTouch but are still concerned about how 'hard' it might be to create a useful application.  One of the applications I am currently working on uses the IPhone's inbuilt GPS and I wanted to show not only how easy it is to get this data, but how understandable the code will be for anyone with a .Net background.

First we add a reference to MonoTouch.CoreLocation with the standard 'using' syntax;

using MonoTouch.CoreLocation;

We then create a module level instance of the location manager:

private CLLocationManager locManager = new CLLocationManager();

We can start the GPS location tracking:

locManager.StartUpdatingLocation();

After which we can access our latitude and longitude:

if (locManager != null)
{
  string lat = locManager.Location.Coordinate.Latitude;
  string lng =locManager.Location.Coordinate.Longitude;
}

This article is based on information I initially read on the following University of Texas at San Antonio blog.