fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<Integer> routeLine = new ArrayList<Integer>();
  13. routeLine.add(0);
  14. routeLine.add(1);
  15. routeLine.add(2);
  16. routeLine.add(3);
  17. routeLine.add(4);
  18. routeLine.add(5);
  19.  
  20. String result = Arrays.toString(routeLine.subList(4,6).toArray());
  21.  
  22. //Baidu
  23. // result = String.valueOf(gps2d(24.189407,120.710013,24.189367,120.71));
  24. // result = String.valueOf(gps2d(24.189407,120.710013,24.188386,120.710014));
  25. //Google
  26. result = String.valueOf(gps2d(6.059924, 125.417117,-35.954718, 85.338992));
  27.  
  28. System.out.println(result);
  29. }
  30.  
  31. private static double gps2d(double lat_a, double lng_a, double lat_b, double lng_b) {
  32. double d = 0;
  33. lat_a=lat_a*Math.PI/180;
  34. lng_a=lng_a*Math.PI/180;
  35. lat_b=lat_b*Math.PI/180;
  36. lng_b=lng_b*Math.PI/180;
  37.  
  38. d=Math.sin(lat_a)*Math.sin(lat_b)+Math.cos(lat_a)*Math.cos(lat_b)*Math.cos(lng_b-lng_a);
  39. d=Math.sqrt(1-d*d);
  40. d=Math.cos(lat_b)*Math.sin(lng_b-lng_a)/d;
  41. d=Math.asin(d)*180/Math.PI;
  42.  
  43. if (lat_b >= lat_a) {
  44. if (d < 0) {
  45. d = 360 + d;
  46. }
  47. } else {
  48. d = 180 - d;
  49. }
  50.  
  51. // d = Math.round(d*10000);
  52. return d;
  53. }
  54. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
218.7547880629748