Java Decimal Format adjust(Double lng, Double lat, Double distance, Double angle)

Here you can find the source of adjust(Double lng, Double lat, Double distance, Double angle)

Description

adjust

License

Apache License

Declaration

public static Double adjust(Double lng, Double lat, Double distance, Double angle) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    private static final double EARTH_RADIUS = 6378137;
    public static final double POLAR_RADIUS = 6356725;
    public static final DecimalFormat df = new DecimalFormat("#.000000");

    public static Double adjust(Double lng, Double lat, Double distance, Double angle) {
        double dx = distance * 1000 * Math.sin(angle * Math.PI / 180);
        double dy = distance * 1000 * Math.cos(angle * Math.PI / 180);
        double lon1 = (dx / Ed(lat) + rad(lng)) * 180 / Math.PI;
        double lat1 = (dy / Ec(lat) + rad(lat)) * 180 / Math.PI;

        if (angle == 0 || angle == 180) {
            return Double.parseDouble(df.format(lat1));
        } else {/* w w w. jav  a2  s .c  o m*/
            return Double.parseDouble(df.format(lon1));
        }
    }

    private static double Ed(Double lat) {
        return Ec(lat) * Math.cos(rad(lat));
    }

    private static double rad(double d) {
        return d * Math.PI / 180.0;
    }

    private static double Ec(Double lat) {
        return POLAR_RADIUS + (EARTH_RADIUS - POLAR_RADIUS) * (90 - lat) / 90;
    }
}

Related

  1. addDouble(Integer i, Double d)
  2. adjustDoubleNumber(Double doubleNumber, int maxIntPart, int maxFloatPart)
  3. createMeanRmsString(double values[])
  4. decimal2percent(double decimal, int pos)
  5. decimal2string(BigDecimal arg, Locale loc)