0

i am asked to show a gps device on a google map. i have written a listener and the format looks something like this

1724.1543,N,07822.4276,E

how to convert these into degrees, minutes and seconds format like

17.241543,78.224276

Apparently google maps recognizes lat lng in the above format only.

My listener is written in nodejs, so a javascript way to convert is more appreciated.

thanks.

Lakshman Pilaka
  • 1,803
  • 2
  • 24
  • 48
  • Possible duplicate of [Converting latitude and longitude to decimal values](http://stackoverflow.com/questions/1140189/converting-latitude-and-longitude-to-decimal-values) – ssc-hrep3 Jan 08 '17 at 12:11

1 Answers1

0

javascript way to convert lat and long to degree,minute and second is as follows:

//to convert pass lat or long to this function

function DECtoDMS(dd)
{
    var vars  = dd.split('.');
    var deg   = vars[0];
    var tempma = "0."+vars[1];
    tempma = tempma * 3600;
    var min = Math.floor(tempma / 60);
    var sec = tempma - (min * 60);
    return deg+"-"+min+"-"+sec;
}

//call the function

var inDeg  = DECtoDMS(72.8479400);
console.log(inDeg);
Codesingh
  • 3,316
  • 1
  • 11
  • 18