JavaScript Coordinate Conversion Engine — Developer Guide

This page documents the JavaScript conversion engine that actually powers Coordinate-Converter.com: a single client-side file, /static/calculations.js, whose functions run in the visitor's browser.

No hosted REST API

Coordinate-Converter.com does not offer a hosted REST API. There is no server endpoint to send requests to, no API key, and no server-side conversion service. All conversions on this site run locally in your browser using the JavaScript engine documented below — your coordinates are not sent to a server. An earlier version of this page described a REST endpoint that does not exist; that description was wrong and has been removed.

Loading the engine

The engine is one plain JavaScript file — the same file this page and the site's converter tools load. Include it with a script tag and its functions become available as globals on window:

<script src="https://www.coordinate-converter.com/static/calculations.js"></script>
<script>
  const utm = window.LLtoUTM(35.6812, 139.7671);
  console.log(utm.zoneNumber, utm.zoneLetter, utm.easting, utm.northing);
</script>

There is no npm package, SDK download, or API key for this engine. It is an IIFE that attaches functions and constants (such as WGS84) to window (or self in a worker).

Functions the engine actually exposes

Verified against static/calculations.js as served by this site. Only the functions listed here exist; anything else is not part of the engine.

FunctionParametersReturns
LLtoUTM(lat, lon)Latitude and longitude in decimal degrees (WGS84)Object { easting, northing, zoneNumber, zoneLetter, zone, hemi } — metres, UTM zone number and latitude band letter
UTMtoLL(easting, northing, zoneNumber, zoneLetter)UTM easting/northing in metres, zone number (1–60), band letter (e.g. "S")Object { lat, lon } in decimal degrees
LLtoMGRS(lat, lon, accuracy)Decimal degrees; optional accuracy 0–5 (default 5). Also accepts a [lon, lat] array or a { lat, lon } object as the first argumentMGRS string, e.g. 54S UE 88433 49290. Returns the string "Polar Region (Not Supported)" outside the MGRS latitude range
MGRStoLL(mgrsString)An MGRS string such as "54S UE 88433 49290" (spaces optional)Object { lat, lon } for the referenced grid cell. Throws an Error on an invalid MGRS string
DMStoDeg(d, m, s, dir)Degrees, minutes, seconds, and an optional hemisphere letter ("N", "S", "E", "W")Decimal degrees as a number; negative for S/W or a negative degree value
DegtoDMS(deg, isLat)Decimal degrees; isLat selects N/S (true) or E/W (false) hemisphere lettersObject { d, m, s, isNegative, hemisphere, toString() }
LLtoWebMercator(lat, lon)Decimal degreesObject { x, y } in EPSG:3857 metres. Throws an Error if |lat| > 85.06
WebMercatorToLL(x, y)EPSG:3857 metresObject { lat, lon } in decimal degrees
vincentyInverse(lat1, lon1, lat2, lon2)Two points in decimal degreesObject { distance, initialBearing, finalBearing } — geodesic distance in metres (Vincenty, WGS84), bearings in degrees
haversineDistance(lat1, lon1, lat2, lon2)Two points in decimal degreesGreat-circle distance in metres (number)
wgs84ToTokyo(lat, lon) / tokyoToWgs84(lat, lon)Decimal degreesObject { lat, lon } — 3-parameter datum shift between WGS84 and the Tokyo Datum
nad83ToWgs84(lat, lon, h) / wgs84ToNad83(lat, lon, h)Decimal degrees; height h optional (default 0)Object { lat, lon, h, shiftMeters }

The engine also exposes regional datum helpers (sk42ToWGS84, dgn95ToSrgi2013, kalianpurToWGS84, amersfoortToWGS84), survey helpers (getElevationFactor, getUTMGridScaleFactor, getCombinedScaleFactor, getConvergenceAngle), vertical-datum approximations (navd88ToNgvd29, ngvd29ToNavd88), and the constants WGS84, BESSEL and GRS80.

Worked example (real output)

Tokyo Station, 35.6812, 139.7671, run through the actual engine:

window.LLtoUTM(35.6812, 139.7671);
// {
//   easting: 388433.374620894,
//   northing: 3949290.0136118084,
//   zoneNumber: 54,
//   zoneLetter: "S",
//   zone: 54,
//   hemi: "S"
// }

window.LLtoMGRS(35.6812, 139.7671, 5);
// "54S UE 88433 49290"

window.MGRStoLL("54S UE 88433 49290");
// { lat: 35.68119983576186, lon: 139.7670958628666 }

window.DegtoDMS(35.6812, true).toString();
// 35° 40' 52.32" N

Need programmatic conversion in your own project?

This site has no server-side API to call. The realistic options are:

  • Many rows at once, in the browser: the site's Batch Converter converts an uploaded CSV locally in your browser.
  • JavaScript / Node.js: use the established open-source proj4 package (a JavaScript port of PROJ) for general CRS conversion, and the mgrs package for MGRS forward and reverse conversion.
  • Python: use pyproj (a wrapper for PROJ) — see this site's Python conversion guide, which is a guide to pyproj, not an SDK provided by this site.
  • This site's engine: load /static/calculations.js as shown above and call the documented functions directly in the browser.

Browser Demo

Runs 100% locally with this site's JavaScript engine (calculations.js). Nothing is sent to a server — there is no API behind this demo.

Format: latitude, longitude in decimal degrees (example: Tokyo Station).