The angle between two famous android geolocations

I want to find the angle between two famous geolocations. In any case, I want to direct the arrow, whose tail is at my current location, and the arrow is aimed at a fixed geolocation. Therefore, I think that if one way or another, I can get the angle between these two geolocations, then I will be able to do the same.

You guys have suggestions to make this better. Any help would be appreciated.

+2
source share
4 answers

. :

private double angleFromCoordinate(double lat1, double long1, double lat2,
        double long2) {

    double dLon = (long2 - long1);

    double y = Math.sin(dLon) * Math.cos(lat2);
    double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
            * Math.cos(lat2) * Math.cos(dLon);

    double brng = Math.atan2(y, x);

    brng = Math.toDegrees(brng);
    brng = (brng + 360) % 360;
    brng = 360 - brng;

    return brng;
}

ImageView

private void rotateImage(ImageView imageView, double angle) {

    Matrix matrix = new Matrix();
    imageView.setScaleType(ScaleType.MATRIX); // required
    matrix.postRotate((float) angle, imageView.getDrawable().getBounds()
            .width() / 2, imageView.getDrawable().getBounds().height() / 2);
    imageView.setImageMatrix(matrix);
}
+1

I'm not sure I understand what you want to do, but check this out: Android Reference, Location, distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float [])

the result parameter should be an array of floats - at least 2 elements. Then in results [0] you will find the distance in results 1 lying between these two points. What's important "Distance and bearing are determined using the ellipsoid WGS84."

0
source

All Articles