2

I want to make a function that calculate the angle between the user and one point of interest (POI) with reference to the true north.

I already have the longitude and latitude of my position and the POI position and now i need the angle between them.

Here is what i have:

private float calcAzimuth1(float lat0, float long0, float lat1, float long1)
{
    //user's latitude and longitude
    float userLat  = (float) ((lat0  * ((float)Math.PI))/180);
    float userLong = (float) ((long0 * ((float)Math.PI))/180);

    //POI's latitude and longitude
    float latT1    = (float) ((lat1  * ((float)Math.PI))/180);
    float longT1   = (float) ((long1 * ((float)Math.PI))/180);

    //angle between them
    float angle=??}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ricardo
  • 121
  • 1
  • 2
  • 11
  • 1
    Angle between them with reference to what? – slybloty May 18 '12 at 17:41
  • Sorry i forgot! With reference to the true north! – Ricardo May 18 '12 at 18:01
  • 1
    This is actually fairly tricky. A degree of longitude varies from 60 nautical miles at the equator to zero at the poles, so conversion to a local rectangular ratio of distances requires taking that into account before you take the arctangent. But over longer distances, making a local rectangular projection is no longer valid. This was thought through in some places in antiquity, and common knowledge of age-of-sail navigators, so a good navigation primer should give what you need. Paging Nathaniel Bowditch... http://en.wikisource.org/wiki/The_American_Practical_Navigator – Chris Stratton May 18 '12 at 18:25

1 Answers1

1

Check bearingTo function of Location class http://developer.android.com/reference/android/location/Location.html#bearingTo(android.location.Location) You can create two Location objects from your Lat/Longs and then get the bearing between them.

The other thing you might need is to calculate the device orientation and then combine them together. That requires listening to Sensors and calculating the North from the information received. check the answer here: Compass readings on SGS III

Community
  • 1
  • 1
Raanan
  • 4,777
  • 27
  • 47