计算两个点之前的距离
This commit is contained in:
parent
1972c0d453
commit
a22e22a15b
|
|
@ -0,0 +1,29 @@
|
|||
namespace LY.App.Common
|
||||
{
|
||||
public static class GisHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 计算两点之间的距离
|
||||
/// </summary>
|
||||
/// <param name="lat1"></param>
|
||||
/// <param name="lon1"></param>
|
||||
/// <param name="lat2"></param>
|
||||
/// <param name="lon2"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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; }
|
||||
/// <summary>
|
||||
/// #距离飞手的距离
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public double distance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ,#东向速度
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
//推送报警信息
|
||||
|
|
|
|||
Loading…
Reference in New Issue