Transforming business operations through innovation

Developer Blog

Tips and tricks for developers.

Converting Coordinates to MGRS in C#

Converting standard latitude and longitude coordinates into MGRS in C# is a piece of cake. With the awesome CoordinateSharp .NET library, you can do it with minimal code.

Step 1

To get started, download the CoordinateSharp nuget package via your developer environment’s nuget package installer.


Step 2

Add the below using statements to your code.

using CoordinateSharp;

Step 3

Create a Coordinate and convert to MGRS format.

//Create a coordinate object with a defined latitude and longitude
Coordinate c = new Coordinate(40.57682, -70.75678);

//Output in MGRS format
c.MGRS.ToString(); // Outputs 19T CE 51307 93264

That’s it! While this example is basic, CoordinateSharp can do a lot more to include parsing coordinates from strings, converting to other formats such as UTM and GEOREF. It can even calculate distance and sunset times.

Be sure to check out the CoordinateSharp Developer Guide for more information on converting to and from MGRS.