# How the IntelHUD Computes MGRS and Lat/Lon Coordinates in God's Eye View

> Discover how the IntelHUD computes MGRS and lat/lon coordinates. Learn to extract camera position and convert data formats for real-time geographic tracking.

- Repository: [Bilawal Sidhu/gods-eye-view](https://github.com/bilawalsidhu/gods-eye-view)
- Tags: how-to-guide
- Published: 2026-09-09

---

**The IntelHUD derives real-time geographic coordinates by extracting the Cesium camera's cartographic position, converting radians to decimal degrees, and transforming them into MGRS and DMS formats using the `mgrs` library and native helper methods.**

The `bilawalsidhu/gods-eye-view` repository implements a military-style intelligence heads-up display (HUD) that renders precise geographic coordinates inside a Cesium.js viewport. Understanding how the IntelHUD computes MGRS and lat/lon coordinates reveals a streamlined pipeline that converts raw camera telemetry into human-readable military grid references and degree-minute-second strings.

## Extracting Camera Position from Cesium.js

The coordinate computation begins in the `_updateCameraData` method located at lines 96-100 of [`src/hud.js`](https://github.com/bilawalsidhu/gods-eye-view/blob/main/src/hud.js). This method accesses the camera's underlying cartographic representation through `camera.positionCartographic`, which provides longitude and latitude in radians.

To prepare these values for conversion, the HUD applies `Cesium.Math.toDegrees` to both the longitude and latitude components. This transformation yields decimal degree pairs (e.g., `-77.0365, 38.8977`) that serve as the canonical input for all subsequent coordinate formatting operations.

```javascript
// src/hud.js (lines 96-100)
const camera = viewer.camera;
const cartographic = camera.positionCartographic;
const lonDeg = Cesium.Math.toDegrees(cartographic.longitude);
const latDeg = Cesium.Math.toDegrees(cartographic.latitude);

```

## Converting Decimal Degrees to MGRS

Once the HUD holds decimal degrees, it passes the `[lonDeg, latDeg]` array to the **`mgrs`** library's `forward` function (aliased as `toMGRS` in the codebase) with a precision parameter of `4`. This precision level corresponds to a 10-meter grid resolution, standard for tactical military reference systems.

The raw MGRS string (e.g., `18SUJ23370716`) undergoes formatting in the `_formatMGRS` method (lines 303-308). This helper injects white space between the grid zone designator, the 100-kilometer square identifier, and the numeric easting/northing values to produce a readable format like `18S UJ 23370 70716` before DOM insertion.

```javascript
// MGRS conversion with 10m precision
const rawMGRS = toMGRS([lonDeg, latDeg], 4);
const formattedMGRS = this._formatMGRS(rawMGRS);
document.getElementById('hud-mgrs').textContent = `MGRS: ${formattedMGRS}`;

```

## Formatting Coordinates as DMS

For traditional latitude/longitude display, the IntelHUD relies on the `_toDMS` helper method defined at lines 223-236. This function decomposes a decimal degree value into its **degrees**, **minutes**, and **seconds** components, pads each segment to maintain fixed-width formatting, and appends the correct hemisphere indicator (`N`, `S`, `E`, or `W`).

The method returns formatted strings such as `38°53'23.10"N`, which the HUD injects into the `#hud-latlon` element alongside its counterpart coordinate. This DMS conversion occurs independently of the MGRS calculation, allowing both reference systems to update simultaneously each telemetry tick.

```javascript
// DMS conversion for human-readable display
const latDMS = this._toDMS(latDeg, 'lat');
const lonDMS = this._toDMS(lonDeg, 'lon');
document.getElementById('hud-latlon').textContent = `${latDMS} ${lonDMS}`;

```

## Rendering Coordinates to the HUD Interface

The final stage writes computed values to specific DOM targets within the HUD structure. According to lines 309-322 of [`src/hud.js`](https://github.com/bilawalsidhu/gods-eye-view/blob/main/src/hud.js):

1. **MGRS values** populate `#hud-mgrs` (lines 309-311)
2. **DMS lat/lon pairs** populate `#hud-latlon` (lines 317-319)
3. **Consolidated coordinate line** updates `#hud-bottom-line` (lines 320-322)

This triple-target approach ensures operators can view isolated MGRS references, separate latitude/longitude strings, or a combined bottom-bar summary depending on their operational focus.

## Summary

- The IntelHUD extracts raw camera telemetry via `camera.positionCartographic` and converts radians to decimal degrees using `Cesium.Math.toDegrees`.
- MGRS coordinates are generated through the `mgrs` library's `forward` function with 4-digit precision (10-meter accuracy) and formatted by `_formatMGRS` for readability.
- Latitude and longitude display in DMS format through the `_toDMS` helper, which handles degree decomposition and hemisphere labeling.
- All coordinate strings update synchronously across three DOM elements: `#hud-mgrs`, `#hud-latlon`, and `#hud-bottom-line`.

## Frequently Asked Questions

### What library does the IntelHUD use for MGRS conversion?

The HUD imports the **`mgrs`** npm package (declared in [`package.json`](https://github.com/bilawalsidhu/gods-eye-view/blob/main/package.json)) and utilizes its `forward` function—referenced as `toMGRS` in the source—to convert decimal degree arrays into Military Grid Reference System strings.

### What precision level does the IntelHUD use for MGRS coordinates?

The system invokes `toMGRS([lonDeg, latDeg], 4)`, where the second argument specifies precision level 4. This produces a 10-meter grid square, meaning the final coordinate identifies a 10m × 10m area on the ground.

### How does the IntelHUD convert Cesium's radians to decimal degrees?

Inside `_updateCameraData` at lines 96-100, the code calls `Cesium.Math.toDegrees(cartographic.longitude)` and `Cesium.Math.toDegrees(cartographic.latitude)` to transform the Cesium camera's native radian values into the decimal degree format required by both the MGRS library and the DMS formatter.

### Can the coordinate display format be customized?

While the current implementation hard-codes precision values and formatting patterns in `_formatMGRS` and `_toDMS`, the modular structure of [`src/hud.js`](https://github.com/bilawalsidhu/gods-eye-view/blob/main/src/hud.js) allows developers to adjust precision parameters or modify the regex-based spacing logic in `_formatMGRS` (lines 303-308) to alter the visual presentation of grid coordinates.