The angle between the two GPS coordinates

I am working in another iPhone application that uses AR, and I create my own framework, but I am having problems trying to get the second coordinate angle relative to the current position of the device, does anyone know a good resource that could help me with this?

Thanks in advance!

+4
source share
2 answers

If two points are close enough to each other and different from the poles, you can use a few simple triggers:

float dy = lat2 - lat1;
float dx = cosf(M_PI/180*lat1)*(long2 - long1);
float angle = atan2f(dy, dx);

EDIT: , latN longN - dx dy - , . angle, , . , , 180/M_PI.

+13

Android.

import com.google.android.maps.GeoPoint;
    public double calculateAngle(GeoPoint startPoint, GeoPoint endPoint) {
        double lat1 = startPoint.getLatitudeE6() / 1E6;
        double lat2 = endPoint.getLatitudeE6() / 1E6;
        double long2 = startPoint.getLongitudeE6() / 1E6;
        double long1 = endPoint.getLongitudeE6() / 1E6;
        double dy = lat2 - lat1;
        double dx = Math.cos(Math.PI / 180 * lat1) * (long2 - long1);
        double angle = Math.atan2(dy, dx);
        return angle;
    }
+1

All Articles