281 views

Skip to first unread message

Aug 4, 2010, 2:05:26 PM8/4/10

to osmdroid

Hi,

here's code for a bearingTo method (similar to distanceTo) for the

GeoPoint class:

---

public double bearingTo(final GeoPoint other)

{

final double lat1 = Math.toRadians(this.mLatitudeE6 / 1E6);

final double long1 = Math.toRadians(this.mLongitudeE6 / 1E6);

final double lat2 = Math.toRadians(other.mLatitudeE6 / 1E6);

final double long2 = Math.toRadians(other.mLongitudeE6 / 1E6);

final double delta_long = long2 - long1;

final double a = Math.sin(delta_long) * Math.cos(lat2);

final double b = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)

* Math.cos(lat2) * Math.cos(delta_long);

final double bearing = Math.toDegrees(Math.atan2(a, b));

final double bearing_normalized = (bearing + 360) % 360;

return bearing_normalized;

}

---

regards,

Martin

--

Martin Preishuber <martin.p...@digiforge.at>

Aug 5, 2010, 10:42:58 AM8/5/10

to osmdroid

Thanks for that Martin.

I've added it, plus some tests.

Neil

On Aug 4, 8:05 pm, "Martin Preishuber"

> Martin Preishuber <martin.preishu...@digiforge.at>

I've added it, plus some tests.

Neil

On Aug 4, 8:05 pm, "Martin Preishuber"

Reply all

Reply to author

Forward

0 new messages

Search

Clear search

Close search

Google apps

Main menu