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

Issue

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

Solution

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;
}

?>

Answered By – johnDoe

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published