0

カスタムコンパス機能を実行したいアプリがあります。場所 A と場所 B があるとします。自分の場所 (場所 A) をマークしてから、ある距離に移動します。コンパスは場所 A を指す必要があります。 qiblacompass 機能ですが、他の場所に移動すると場所 A を指していません ここに私のコードがあります

public static double getDirectionFromNorth(double degLatitude,
                double degLongitude) {


 final double direction_LATITUDE = Math.toRadians(angle_lat);
 double direction_LONGITUDE = Math.toRadians(angle_lng);

            double latitude2 = Math.toRadians(degLatitude);
            double longitude = Math.toRadians(degLongitude);

            double soorat = Math.sin(direction_LONGITUDE - longitude);
            double makhraj = Math.cos(latitude2) * Math.tan(direction_LATITUDE)
                    - Math.sin(latitude2) * Math.cos(direction_LONGITUDE - longitude);
            double returnValue = Math.toDegrees(Math.atan(soorat / makhraj));

            if (latitude2 > direction_LATITUDE) {
                if ((longitude > direction_LONGITUDE || longitude < (Math
                        .toRadians(-180d) + direction_LONGITUDE))
                        && (returnValue > 0 && returnValue <= 90)) {

                    returnValue += 180;

                } else if (!(longitude > direction_LONGITUDE || longitude < (Math
                        .toRadians(-180d) + direction_LONGITUDE))
                        && (returnValue > -90 && returnValue < 0)) {

                    returnValue += 180;

                }

            }
            if (latitude2 < direction_LATITUDE) {

                if ((longitude > direction_LONGITUDE || longitude < (Math
                        .toRadians(-180d) + direction_LONGITUDE))
                        && (returnValue > 0 && returnValue < 90)) {

                    returnValue += 180;

                }
                if (!(longitude > direction_LONGITUDE || longitude < (Math
                        .toRadians(-180d) + direction_LONGITUDE))
                        && (returnValue > -90 && returnValue <= 0)) {

                    returnValue += 180;
                }

            }
            // ***
            return returnValue;
        }

angle_lat と angle_lng は私の場所です緯度、経度、degLatitude、degLongitude は移動したときのもので、GPS から緯度、経度を取得します

このコードの何が問題なのか、または私のタスクを達成するための他の方法を教えてください。

4

1 に答える 1

0

Use this web page to check your code: http://www.movable-type.co.uk/scripts/latlong.html

Then when you know that you correctly calculate the direction between two lat,longs you will realize that this is not sufficient for walking speeds.

Just drive with a car or a train, well above 10km/h, and your algorithm probabyl will work. To caluclate pedestrian walking direction you need a more advanced algorithm, considering more locations of the past e.g 30meters.

But as first shot, why dont you simply take the direction deliveered by the Location attribute: It is called heading or course. Take that, it is more acurate that the direction between two lat/lons. (because the GPS chip internaly, has more information available)

于 2014-12-03T20:07:39.853 に答える