Convert Lat/Lon to MGRS

SwDevMan81 picture SwDevMan81 · Jul 30, 2010 · Viewed 7.6k times · Source

Does anyone know where I could find a library of code for converting Lat/Lon position to Military Grid Reference System (MGRS)? I'm looking for a C# implementation if possible.

Answer

SwDevMan81 picture SwDevMan81 · Mar 31, 2011

We ended up using GeoTrans and create a DLL from the code and using PInvoke to call the functions. We pulled the following from the source incase anyone wanted to know (minimal solution):

  • polarst
  • tranmerc
  • ups
  • utm
  • mgrs

The PInvoke Signature we used:

[DllImport("mgrs.dll")]
public static extern int Convert_Geodetic_To_MGRS(
   double Latitude,
   double Longitude,
   int Precision, // 1 to 5, we used 4 (10 square meters)
   StringBuilder MGRS);

which corresponds to this function in mgrs.h:

MGRSDLL_API long __stdcall Convert_Geodetic_To_MGRS(
   double Latitude,
   double Longitude,
   long Precision,
   char* MGRS);