Find location 1 Km away in 180 degree (South) from

2019-08-01 01:40发布

I have one Location (lat and long) and I want to find the next location(lat and long), which is 1 km away in 180 degree (in south) from my location(lat and long). Can you give me and algorithm or function?

3条回答
干净又极端
2楼-- · 2019-08-01 02:22

For an easy solution have a look at the SimpleLatLng library and its travel() method:

/**
     * <p>
     * Calculate the end point of traveling along a great-circle path from a
     * given starting point with a given intitial bearing for a known distance.
     * </p>
     * 
     * @param start
     *            the starting point.
     * @param initialBearing
     *            the initial bearing.
     * @param distance
     *            the distance to travel.
     * @param unit
     *            the unit in which distance is measured.
     * @return the end point.
     */
    public static LatLng travel(LatLng start, double initialBearing, double distance,
            LengthUnit unit) {
        double bR = Math.toRadians(initialBearing);
        double lat1R = Math.toRadians(start.getLatitude());
        double lon1R = Math.toRadians(start.getLongitude());
        double dR = distance / LatLngConfig.getEarthRadius(unit);

        double a = Math.sin(dR) * Math.cos(lat1R);
        double lat2 = Math.asin(Math.sin(lat1R) * Math.cos(dR) + a * Math.cos(bR));
        double lon2 = lon1R
                + Math.atan2(Math.sin(bR) * a, Math.cos(dR) - Math.sin(lat1R) * Math.sin(lat2));
        return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2));
    }

You just give it the starting point, direction, distance and unit and you get the calculated location. You'll need to get the complete library as this method uses some classes declared by the library. It has some other useful calculations too.

It's available under the Apache 2.0 License.

查看更多
相关推荐>>
3楼-- · 2019-08-01 02:25

Start with the Rosetta code implementation in Java:

public static double haversine(double lat1, double lon1, double lat2, double lon2) {
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    lat1 = Math.toRadians(lat1);
    lat2 = Math.toRadians(lat2);

    double a = Math.pow(Math.sin(dLat / 2),2) + Math.pow(Math.sin(dLon / 2),2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
}

If you know that lon1 == lon2, then an awful lot of this code drops right out, because dLon == 0:

public static double haversine(double lat1, double lat2) {
    double dLat = Math.toRadians(lat2 - lat1);
    return R * dLat;
}

(which should be familiar as the length = Radius * angle in radians formula)

So, if you know that R = 6372.8, and your desired result is 1, then it is easy to come up with a value for dLat:

dLat = 1.0 / 6372.8;

In other words, simply subtract 1.0 / 6372.8 from your current latitude (and remember to handle points of latitude less than 180 - 1.0 / 6372.8 carefully).

查看更多
Viruses.
4楼-- · 2019-08-01 02:31

Moving due South, also due North, makes the calculation simple as it avoids using longitude. See

1 kms is equal to 0.0088339 degrees.

So in the the Northern hemisphere subtract 0.0088339 from the latitude of location and leave longitude as is. For Southern Hemisphere add 0.0088339.

查看更多
登录 后发表回答