Determinate a Geopoint from another, a distance, and a polar angle
Asked Answered
B

2

6

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(...).

Bible answered 26/2, 2012 at 11:35 Comment(0)
A
1

Take a look at great-circle formulas: http://en.wikipedia.org/wiki/Great-circle_distance

This should give You some hints on how to calculate the distances.

For a point in a given distance and heading, check http://williams.best.vwh.net/avform.htm#LL Those formulas look quite complicated, but are easy to implement ;)

Annam answered 26/2, 2012 at 11:41 Comment(2)
I implemented this for a project at work. Therefore, I am sorry to say that I cannot share the code.Annam
I already shared my code below ... I hope that will save some time to further users ;)Babylonian
B
6

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;
}
Babylonian answered 9/7, 2013 at 10:32 Comment(0)
A
1

Take a look at great-circle formulas: http://en.wikipedia.org/wiki/Great-circle_distance

This should give You some hints on how to calculate the distances.

For a point in a given distance and heading, check http://williams.best.vwh.net/avform.htm#LL Those formulas look quite complicated, but are easy to implement ;)

Annam answered 26/2, 2012 at 11:41 Comment(2)
I implemented this for a project at work. Therefore, I am sorry to say that I cannot share the code.Annam
I already shared my code below ... I hope that will save some time to further users ;)Babylonian

© 2022 - 2024 — McMap. All rights reserved.