Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determinate a Geopoint from another, a distance, and a polar angle

I'm working on an Android app that uses Geopoints and I want to determinate a Geopoint from another Geopoint, a distance (in any format) and a polar angle. For example, I want to get coordinates of a place 100 meters in the North-North-East (22,5 degres) of my location got by the GPS in my phone.

The only method I've found is Location.distanceBetween(...).

like image 785
Edouard Garraud Avatar asked Feb 26 '12 11:02

Edouard Garraud


People also ask

What is the distance between two latitude longitude points?

Each degree of latitude is approximately 69 miles (111 kilometers) apart. At the equator, the distance is 68.703 miles (110.567 kilometers). At the Tropic of Cancer and Tropic of Capricorn (23.5 degrees north and south), the distance is 68.94 miles (110.948 kilometers).

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

I found the following formula: function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) { var R = 6371; // Radius of the earth in km var dLat = deg2rad(lat2-lat1); // deg2rad below var dLon = deg2rad(lon2-lon1); var a = Math. sin(dLat/2) * Math. sin(dLat/2) + Math. cos(deg2rad(lat1)) * Math.


1 Answers

Implementation for Android. This code is great for Unit Testing in your aplication:

public double radiansFromDegrees(double degrees)
{
    return degrees * (Math.PI/180.0);
}

public double degreesFromRadians(double radians)
{
    return radians * (180.0/Math.PI);
}

public Location locationFromLocation(Location fromLocation, double distance, double bearingDegrees)
{
    double distanceKm = distance / 1000.0;
    double distanceRadians = distanceKm / 6371.0;
    //6,371 = Earth's radius in km
    double bearingRadians = this.radiansFromDegrees(bearingDegrees);
    double fromLatRadians = this.radiansFromDegrees(fromLocation.getLatitude());
    double fromLonRadians = this.radiansFromDegrees(fromLocation.getLongitude());

    double toLatRadians = Math.asin( Math.sin(fromLatRadians) * Math.cos(distanceRadians)
                               + Math.cos(fromLatRadians) * Math.sin(distanceRadians) * Math.cos(bearingRadians) );

    double toLonRadians = fromLonRadians + Math.atan2(Math.sin(bearingRadians)
                                                 * Math.sin(distanceRadians) * Math.cos(fromLatRadians), Math.cos(distanceRadians)
                                                 - Math.sin(fromLatRadians) * Math.sin(toLatRadians));

    // adjust toLonRadians to be in the range -180 to +180...
    toLonRadians = ((toLonRadians + 3*Math.PI) % (2*Math.PI) ) - Math.PI;

    Location result = new Location(LocationManager.GPS_PROVIDER);
    result.setLatitude(this.degreesFromRadians(toLatRadians));
    result.setLongitude(this.degreesFromRadians(toLonRadians));
    return result;
}
like image 159
knagode Avatar answered Sep 28 '22 10:09

knagode