I now have coordinates for some positions as latitude and longitude like this
Lat = 16.0490143029144 Lng = 108.197069205344
I want convert it to degree like this
I don't know how to do it, need your help.
Thank in advance.
I now have coordinates for some positions as latitude and longitude like this
Lat = 16.0490143029144 Lng = 108.197069205344
I want convert it to degree like this
I don't know how to do it, need your help.
Thank in advance.
double lat = -86.0490143029144;
double lon = -45.197069205344;
string latDir = (lat >= 0 ? "N" : "S");
lat = Math.Abs(lat);
double latMinPart = ((lat - Math.Truncate(lat) / 1) * 60);
double latSecPart = ((latMinPart - Math.Truncate(latMinPart) / 1) * 60);
string lonDir = (lon >= 0 ? "E" : "W");
lon = Math.Abs(lon);
double lonMinPart = ((lon - Math.Truncate(lon) / 1 ) * 60);
double lonSecPart = ((lonMinPart - Math.Truncate(lonMinPart) / 1) * 60);
Console.WriteLine(
Math.Truncate(lat) + " " + Math.Truncate(latMinPart) + " " + Math.Truncate(latSecPart) + " " + latDir
);
Console.WriteLine(
Math.Truncate(lon) + " " + Math.Truncate(lonMinPart) + " " + Math.Truncate(lonSecPart) + " " + lonDir
);
Add checks for nulls, zeros and data out of range.