Angle between two known android geolocations

时光怂恿深爱的人放手 提交于 2019-12-01 05:48:05

问题


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 pointing towards a fixed geolocation. So I am thinking if somehow, I am able to get an angle between these two geolocations then propably i will be able to do the same.

Do you guys have some suggestions to do it in a better manner. Any help would be appreciated.


回答1:


Refer to this, there are several approaches explained.

How do I calculate the Azimuth (angle to north) between two WGS84 coordinates




回答2:


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);
}



回答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




回答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."



来源:https://stackoverflow.com/questions/6189258/angle-between-two-known-android-geolocations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!