Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate latitude and longitude having meters distance from another latitude/longitude point

I need to calculate latitude and longitude of a given point.

I know latitude and longitude of a reference point, and an value indicating meters on x and y axis from the reference point. Starting from this data I have to find latitude and longitude of the point.

I searched for similar questions but it looks like most questions are about finding distance between two lat/long points. I need to do the contrary.

How can I do? I use Java

like image 919
Sabrina Avatar asked May 02 '11 13:05

Sabrina


People also ask

How do you find the distance between two latitude longitude points in meters?

For this divide the values of longitude and latitude of both the points by 180/pi. The value of pi is 22/7. The value of 180/pi is approximately 57.29577951. If we want to calculate the distance between two places in miles, use the value 3, 963, which is the radius of Earth.

What is the distance between 2 latitudes?

Lines of latitude are called parallels and in total there are 180 degrees of latitude. The distance between each degree of latitude is about 69 miles (110 kilometers).


1 Answers

Here is the best starting point for such questions: Aviation Formulary. They have all the formulas for doing such kinds of things.

From these formulary, I created my own Java util class. It uses a lot of internal stuff, so I cannot post the actual class here but to give you some examples on how to convert the knowledge from the formulary into Java code.

Here're some basic methods:

/**
 * the length of one degree of latitude (and one degree of longitude at equator) in meters.
 */
private static final int DEGREE_DISTANCE_AT_EQUATOR = 111329;
/**
 * the radius of the earth in meters.
 */
private static final double EARTH_RADIUS = 6378137; //meters
/**
 * the length of one minute of latitude in meters, i.e. one nautical mile in meters.
 */
private static final double MINUTES_TO_METERS = 1852d;
/**
 * the amount of minutes in one degree.
 */
private static final double DEGREE_TO_MINUTES = 60d;


/**
 * This method extrapolates the endpoint of a movement with a given length from a given starting point using a given
 * course.
 *
 * @param startPointLat the latitude of the starting point in degrees, must not be {@link Double#NaN}.
 * @param startPointLon the longitude of the starting point in degrees, must not be {@link Double#NaN}.
 * @param course        the course to be used for extrapolation in degrees, must not be {@link Double#NaN}.
 * @param distance      the distance to be extrapolated in meters, must not be {@link Double#NaN}.
 *
 * @return the extrapolated point.
 */
public static Point extrapolate(final double startPointLat, final double startPointLon, final double course,
                                final double distance) {
    //
    //lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
    //dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat))
    //lon=mod( lon1+dlon +pi,2*pi )-pi
    //
    // where:
    // lat1,lon1  -start pointi n radians
    // d          - distance in radians Deg2Rad(nm/60)
    // tc         - course in radians

    final double crs = Math.toRadians(course);
    final double d12 = Math.toRadians(distance / MINUTES_TO_METERS / DEGREE_TO_MINUTES);

    final double lat1 = Math.toRadians(startPointLat);
    final double lon1 = Math.toRadians(startPointLon);

    final double lat = Math.asin(Math.sin(lat1) * Math.cos(d12)
        + Math.cos(lat1) * Math.sin(d12) * Math.cos(crs));
    final double dlon = Math.atan2(Math.sin(crs) * Math.sin(d12) * Math.cos(lat1),
        Math.cos(d12) - Math.sin(lat1) * Math.sin(lat));
    final double lon = (lon1 + dlon + Math.PI) % (2 * Math.PI) - Math.PI;

    return new Point(Math.toDegrees(lat), Math.toDegrees(lon));
}

/**
 * calculates the length of one degree of longitude at the given latitude.
 *
 * @param latitude the latitude to calculate the longitude distance for, must not be {@link Double#NaN}.
 *
 * @return the length of one degree of longitude at the given latitude in meters.
 */
public static double longitudeDistanceAtLatitude(final double latitude) {

    final double longitudeDistanceScaleForCurrentLatitude = Math.cos(Math.toRadians(latitude));
    return DEGREE_DISTANCE_AT_EQUATOR * longitudeDistanceScaleForCurrentLatitude;
}
like image 109
BertNase Avatar answered Sep 22 '22 04:09

BertNase