I want to find an angle between two known geolocations.Basically what I want is, I want to direct an arrow whose tail point is at my current location and arrow head is point
This is simple trig, really. If they're close enough together, you can just use plane geometry. Take the two locations, figure out the right triangle that has the two locations as the acute angles, and compute.
There's already a link to the basic math up.
One thing -- if the locations are very far apart, you'll want to use spherical trig or the angles will be inaccurate.
Well, there was a link ... http://www.easycalculation.com/trigonometry/triangle-angles.php
I'm not sure that I understand what you want to do, but check this: Android Reference, Location, distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)
results parameter should be array of floats - at least 2 elements. Then in results[0] you will find distance and in results1 bearing between this two points. What is important "Distance and bearing are defined using the WGS84 ellipsoid."
I wanted to achieve the same. using this referance to calculate Angle as follows:
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;
}
and then rotate ImageView to this angle
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);
}
Refer to this, there are several approaches explained.
How do I calculate the Azimuth (angle to north) between two WGS84 coordinates