Calculating the angle between the user and POI (Points of Interest) in android

897 views Asked by At

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=??}
1

There are 1 answers

0
Raanan On

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