This code converts between coordinate systems, particularly Lat/Long and USNG (MGRS). It is extensible, so if you can come up with an algorithm, fork and add it. Details for adding modules are included. Happy hacking!

The algorithms and most of the code is not my own. I have refactored the code to be more module-friendly and I have added a few functions. I mostly consider myself a maintainer of the code, but I feel I have made enough changes so I have changed the copyright notices to be in my name. Appropriate credits have been included in this README under References.

I do not guarantee any of the algorithms to be accurate, and appropriate testing should be done before this module is relied upon for accuracy.

This code is licensed under the MIT license. Please see the LICENSE file for more information.

Conversion support is nowhere near complete. For now, only these conversions are supported.

As you can see, coordinator will give you a function. This is nice because you can load it once and just pass the function around. This simplifies the module a bit as well as expanding your options.

This module assumes a datum of NAD83 (or its international equivalent WGS84). If NAD27 is used instead, set IS_NAD83_DATUM (in constants.js) to 'false'. (This does not do a datum conversion; it only allows either datum to be used for geographic-UTM/USNG calculations.

For detailed information about functions, constants, etc, please see the README in the lib directory. It explains exactly what is in each file.

There are a few files that are of interest for someone adding to the module:

lib/constants.js- has common constants needed for conversion

index.js- main file; this file is the preferred interface

lib/helpers.js- helper functions to reduce clutter

Right now, only lat/long, UTM, and USNG/MGRS are supported:

lib/latlong.js- exports four functions, the most important being getConverter

getConverter- required to integrate with the module; returns conversion function

toUtm- converts lat/long to UTM

toMgrs- converts lat/long to MGRS using UTM in the background

toUsng- converts lat/long to USNG using UTM in the background

lib/usng.js- exports four functions, the most important being getConverter

getConverter- required to integrate with the module; returns conversion function

toUtm- converts USNG coordinate to UTM

toLatLong- converts USNG to lat/long

isUsng- validates an input string. Returns 0 if not valid or the string in upper-case without space delimiters

lib/utm.js- exports two functions, the most important being being getConverter

getConverter- required to integrate with the module; returns conversion function

toLatLong- converts UTM to lat/long

This module assumes a datum of NAD83 (or its international equivalent WGS84).

If NAD27 is used instead, set IS_NAD83_DATUM to 'false'. (This does not do a datum conversion; it only allows either datum to be used for geographic-UTM/USNG calculations. NAD27 computations are irrelevant to Google Maps applications). NAD83 and WGS84 are equivalent for all practical purposes.

Note regarding UTM coordinates: UTM calculations are an intermediate step in lat/lng-USNG conversions. These functions are not exported. If they are used, remember that the functions in this module use negative numbers for UTM Y values in the southern hemisphere. The calling application must check for this, and convert to correct southern-hemisphere values by adding 10,000,000 meters.

This code was originally written by Larry Moore, larmoor@gmail.com, and came from this address: http://dhost.info/usngweb/help_usng.html. The code has undergone some changes (mostly formatting) in order to make it cleaner and to publish it to NPM. If there are any errors, they are probably my fault.