Created
November 22, 2016 05:56
-
-
Save fajarlabs/0ecd153ce3a46d40e380a02569414bfb to your computer and use it in GitHub Desktop.
Convert Latitude or Longitude to DMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.DecimalFormat; | |
public class DMSConverter { | |
public static DecimalFormat df = new DecimalFormat("#"); | |
public static String lat(double vLat) { | |
double convertLat = Math.abs(vLat); | |
double dl = Math.floor(convertLat); | |
double minFloatL = (convertLat - dl) * 60; | |
double ml = Math.floor(minFloatL); | |
double secFloatL = (minFloatL-ml) * 60; | |
double sl = secFloatL; | |
String LatCardinal = ((vLat > 0) ? "N" : "S"); | |
return df.format(dl)+"° "+df.format(ml)+"' "+df.format(sl)+"\""+" "+LatCardinal; | |
} | |
public static String lon(double vLng) { | |
double convertLng = Math.abs(vLng); | |
double dg = Math.floor(convertLng); | |
double minFloatG = (convertLng - dg) * 60; | |
double mg = Math.floor(minFloatG); | |
double secFloatG = (minFloatG-mg) * 60; | |
double sg = secFloatG; | |
String LngCardinal = ((vLng > 0) ? "E" : "W"); | |
return df.format(dg)+"° "+df.format(mg)+"' "+df.format(sg)+"\""+" "+LngCardinal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment