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

NajLinus picture NajLinus · Mar 28, 2016 · Viewed 32.2k times · Source

I have latitude and longitude of NMEA format, and I want to convert it into decimal value. Is there any formula? For example, NMEA format Latitude = 35.15 N and Longitude = 12849.52 E

Answer

johnDoe picture johnDoe · Mar 28, 2016

The format for NMEA coordinates is (d)ddmm.mmmm
d=degrees and m=minutes
There are 60 minutes in a degree so divide the minutes by 60 and add that to the degrees.

For the Latitude=35.15 N
35.15/60 = .5858 N

For the Longitude= 12849.52 E,
128+ 49.52/60 = 128.825333 E

In php, you could do this:

<?php
$lng = "12849.52 W";

$brk = strpos($lng,".") - 2;
if($brk < 0){ $brk = 0; }

$minutes = substr($lng, $brk);
$degrees = substr($lng, 0,$brk);

$newLng = $degrees + $minutes/60;

if(stristr($lng,"W")){
    $newLng = -1 * $newLng;
}

?>