diff --git a/Common/GisHelper.cs b/Common/GisHelper.cs
new file mode 100644
index 0000000..1f392b2
--- /dev/null
+++ b/Common/GisHelper.cs
@@ -0,0 +1,29 @@
+namespace LY.App.Common
+{
+ public static class GisHelper
+ {
+ ///
+ /// 计算两点之间的距离
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static double HaversineDistance(double lat1, double lon1, double lat2, double lon2)
+ {
+ const double R = 6371000.0; // 地球半径(单位:米)
+
+ double dLat = ToRadians(lat2 - lat1);
+ double dLon = ToRadians(lon2 - lon1);
+
+ double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
+ Math.Cos(ToRadians(lat1)) * Math.Cos(ToRadians(lat2)) *
+ Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
+
+ double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
+ return R * c;
+ }
+ static double ToRadians(double degrees) => degrees * Math.PI / 180.0;
+ }
+}
diff --git a/Model/Alarm.cs b/Model/Alarm.cs
index f79af3b..258881d 100644
--- a/Model/Alarm.cs
+++ b/Model/Alarm.cs
@@ -37,6 +37,11 @@ namespace LY.App.Model
public double altitude { get; set; }
public double home_lat { get; set; }
public double home_lon { get; set; }
+ ///
+ /// #距离飞手的距离
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public double distance { get; set; }
///
/// ,#东向速度
diff --git a/Service/AlarmService.cs b/Service/AlarmService.cs
index 5e69b68..424e771 100644
--- a/Service/AlarmService.cs
+++ b/Service/AlarmService.cs
@@ -57,6 +57,7 @@ namespace LY.App.Service
item.positionId = deviceinfo.PositionId;
item.PostionName = deviceinfo.PositionName;
item.Time = input.time;
+ item.distance = GisHelper.HaversineDistance(item.drone_lat, item.drone_lon, item.app_lat,item.app_lon);
}
await _db.CopyNew().Insertable(entity).SplitTable().ExecuteReturnSnowflakeIdListAsync();
//推送报警信息