How to convert latitude and longitude of NMEA format data to decimal?

How to convert latitude and longitude of NMEA format data to decimal?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding NMEA Coordinates: From S Degrees to Decimal Degrees

NMEA (National Marine Electronics Association) sentences are ubiquitous in maritime navigation and IoT tracking, yet their coordinate format often trips up developers expecting standard decimal degrees. When you encounter a string like 3515.0,N or 12849.5,E, the values aren't immediately usable for mapping libraries like Leaflet, Google Maps, or Laravel's geospatial helpers without conversion. The core issue is that NMEA represents coordinates as Degrees and Tenths of Minutes (DM.M), whereas modern APIs require Decimal Degrees (DD).

Understanding the NMEA Structure

The example provided in your inquiry shows a latitude of 35.15 N and a longitude of 12849.52 E. However, standard NMEA sentences usually split these into degrees and minutes/tenths explicitly. A typical $GPGGA sentence might look like this:

$GPGGA,123519,3515.0,N,12849.5,E,1,08,0.9,545.4,M,37.4,H,,,,*6C

Here, the latitude is 3515.0 and the longitude is 12849.5. The comma after the value indicates North (N) or South (S), and similarly for East/West.

The format is Degrees + Minutes. Specifically, the integer part represents degrees, and the fractional part represents tenths of a minute. To convert this to decimal degrees, you must treat the input as a single number where the decimal point is actually a separator between degrees and tenths-of-minutes.

The Conversion Formula

The mathematical relationship relies on the fact that there are 60 minutes in one degree. Since NMEA provides tenths of minutes, you first convert those tenths into full minutes by multiplying by 10, then divide by 60 to get the fractional degree component.

The general formula is:
$$ \text{Decimal} = \text{Degrees} + \left( \frac{\text{Tenths}}{10} \times \frac{1}{60} \right) $$

Simplified, this becomes:
$$ \text{Decimal} = \text{Degrees} + \left( \frac{\text{Tenths}}{600} \right) $$

Handling Direction (N/S/E/W)

The letters N, S, E, and W indicate the hemisphere. This determines the sign of the final value:

  • North and East: Positive values.
  • South and West: Negative values.

Applying this to your example where Latitude = 3515.0,N:

  1. Extract degrees: 35
  2. Extract tenths: 15.0
  3. Calculate minutes fraction: $15.0 / 600 = 0.025$
  4. Combine: $35 + 0.025 = 35.025$
  5. Apply direction: Positive because it is North.

For Longitude 12849.5,E:

  1. Extract degrees: 128
  2. Extract tenths: 49.5
  3. Calculate minutes fraction: $49.5 / 600 = 0.0825$
  4. Combine: $128 + 0.0825 = 128.0825$
  5. Apply direction: Positive because it is East.

Implementation in PHP and Laravel

If you are building a backend in Laravel to ingest GPS data, you can encapsulate this logic in a helper function. This ensures consistency across your application regardless of the NMEA parsing library you use.

function nmeaToDecimal($degreesTenths, $direction)
{
    // Split the string if it hasn't been parsed yet, 
    // though often NMEA parsers return just the number string.
    // Assuming input is a float like 3515.0
    
    $degrees = floor($degreesTenths);
    $tenths = fmod($degreesTenths, 100) / 10; // Extract tenths part (e.g., 15.0 from 3515.0)
    
    // Apply the conversion formula
    $decimalDegrees = $degrees + ($tenths / 600);
    
    // Adjust sign based on direction
    if (in_array($direction, ['S', 'W'])) {
        return -$decimalDegrees;
    }
    
    return $decimalDegrees;
}

Trade-offs and Pitfalls

One common mistake is assuming the input string always contains a decimal point. In some NMEA sentences, minutes might be integers (e.g., 3515,N). The logic remains the same, but your parsing step needs to handle both 3515 and 3515.0. Using standard PHP arithmetic on the raw float usually handles this gracefully if you parse the degrees and minutes separately first.

Another pitfall is precision. NMEA data is often accurate only to about 1 meter (depending on the antenna quality). Converting it to high-precision decimal degrees creates a false sense of accuracy. If your application requires sub-meter precision, you might need to apply corrections based on the device's reported horizontal dilution of precision (HDOP), which is also part of the NMEA $GPGGA sentence.

Why This Matters for Integration

Mapping services like Mapbox or OpenStreetMap expect inputs in WGS84 Decimal Degrees. Sending raw NMEA values directly will place markers hundreds of kilometers away from their actual location. By normalizing this data into decimal degrees, you bridge the gap between legacy maritime protocols and modern web APIs. Whether you are building a fleet tracking dashboard or integrating a marine GPS module with a Laravel API, this conversion step is non-negotiable for accurate geospatial rendering.

For further reading on handling complex NMEA parsing in PHP, check out resources like https://laravelcompany.com which often covers backend integration patterns for IoT devices.

Our network