Angle Between Two Known Android Geolocations
Solution 1:
Refer to this, there are several approaches explained.
How do I calculate the Azimuth (angle to north) between two WGS84 coordinates
Solution 2:
I wanted to achieve the same. using this referance to calculate Angle as follows:
privatedoubleangleFromCoordinate(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
privatevoidrotateImage(ImageView imageView, double angle) {
Matrixmatrix=newMatrix();
imageView.setScaleType(ScaleType.MATRIX); // required
matrix.postRotate((float) angle, imageView.getDrawable().getBounds()
.width() / 2, imageView.getDrawable().getBounds().height() / 2);
imageView.setImageMatrix(matrix);
}
Solution 3:
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
Solution 4:
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."
Post a Comment for "Angle Between Two Known Android Geolocations"