【问题标题】:how to find Qibla angle in Flutter Qibla如何在 Flutter Qibla 中找到 Qibla 角度
【发布时间】:2021-07-01 04:09:04
【问题描述】:
#这是我当前获取角度的代码,但这是十进制值,我想从 1 度到 360 度获取角度#
最终qiblahDirection = 快照.data;
var _angle = ((qiblahDirection.qiblah ?? 0) * (pi / 180) * -1
【问题讨论】:
标签:
flutter
flutter-layout
flutter-dependencies
flutter-animation
flutter-test
【解决方案1】:
double calculateQiblaDirection(Coordinates coordinates) {
// Equation from "Spherical Trigonometry For the use of colleges and schools" page 50
final longitudeDelta =
radians(makkah.longitude) - radians(coordinates.longitude);
final latitudeRadians = radians(coordinates.latitude);
final term1 = sin(longitudeDelta);
final term2 = cos(latitudeRadians) * tan(radians(makkah.latitude));
final term3 = sin(latitudeRadians) * cos(longitudeDelta);
final angle = atan2(term1, term2 - term3);
return DoubleUtil.unwindAngle(degrees(angle));
}
class DoubleUtil {
static double normalizeWithBound(double value, double max) {
return value - (max * ((value / max).floorToDouble()));
}
static double unwindAngle(double value) {
return normalizeWithBound(value, 360);
}
static double closestAngle(double angle) {
if (angle >= -180 && angle <= 180) {
return angle;
}
return angle - (360 * (angle / 360).roundToDouble());
}
}