1. public class GCJ2WGS {
    2. public static void main(String[] args) {
    3. GCJ2WGS wg = new GCJ2WGS();
    4. HashMap<String, Double> hm = wg.delta(38.123456,114.654321);
    5. System.out.println(hm);
    6. }
    7. //圆周率 GCJ_02_To_WGS_84
    8. double PI = 3.14159265358979324;
    9. /**
    10. * @author 作者:
    11. * 方法描述:方法可以将高德地图SDK获取到的GPS经纬度转换为真实的经纬度,可以用于解决安卓系统使用高德SDK获取经纬度的转换问题。
    12. * @param 需要转换的经纬度
    13. * @return 转换为真实GPS坐标后的经纬度
    14. * @throws <异常类型> {@inheritDoc} 异常描述
    15. */
    16. public HashMap<String, Double> delta(double lat,double lon) {
    17. double a = 6378245.0;//克拉索夫斯基椭球参数长半轴a
    18. double ee = 0.00669342162296594323;//克拉索夫斯基椭球参数第一偏心率平方
    19. double dLat = this.transformLat(lon - 105.0, lat - 35.0);
    20. double dLon = this.transformLon(lon - 105.0, lat - 35.0);
    21. double radLat = lat / 180.0 * this.PI;
    22. double magic = Math.sin(radLat);
    23. magic = 1 - ee * magic * magic;
    24. double sqrtMagic = Math.sqrt(magic);
    25. dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI);
    26. dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
    27. HashMap<String, Double> hm = new HashMap<String, Double>();
    28. hm.put("lat",lat - dLat);
    29. hm.put("lon",lon - dLon);
    30. return hm;
    31. }
    32. //转换经度
    33. public double transformLon(double x, double y) {
    34. double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
    35. ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
    36. ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0;
    37. ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0;
    38. return ret;
    39. }
    40. //转换纬度
    41. public double transformLat(double x, double y) {
    42. double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
    43. ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
    44. ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
    45. ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
    46. return ret;
    47. }
    48. }


    /
    将经纬度转换为度分秒格式
    _
    @param du 116.418847
    *
    @return 116°25’7.85”
    /
    _fun changeToDFM(du: Double): String? {
    val du1 = du.toInt()
    val tp = (du - du1)
    60
    val fen = tp.toInt()
    val miao =
    String._format
    (“%.2f”, Math.abs((tp - fen) * 60))
    return du1.toString() + “°” + Math.abs(fen) + “‘“ + miao + “\””
    }
    _/

    将经纬度转换为度分秒格式
    @param _du 116.418847
    *
    @return _116°25’7”,E
    /
    _fun changeToDFM(du: Double, isLat: Boolean): String? {
    val d = if (isLat) {
    if (du > 0) {
    “N”
    } else {
    “S”
    }
    } else {
    if (du > 0) {
    “E”
    } else {
    “W”
    }
    }
    val du1 = du.toInt()
    val tp = (du - du1)
    60
    val fen = tp.toInt()
    val miao = Math.abs((tp - fen) * 60).toInt()
    return du1.toString() + “°” + Math.abs(fen) + “‘“ + miao + “\”” + “,$d”
    }