我有两个GPS坐标,我想计算它们之间的距离,但SQL服务器上的结果与c#中的结果完全不同,我用Google搜索,发现这两种方法都以米为单位返回距离,但这种差异让我发疯.
SQL SERVER查询
select geography::Point(25.3132666, 55.2994054 ,4326)
.STDistance(geography::Point(25.25434, 55.32820,4326)) as Distance;
Run Code Online (Sandbox Code Playgroud)
Web API
String format = "POINT(25.25434 55.32820)";
DbGeography myLocation = DbGeography.PointFromText(format, 4326);
var users = context.Users.Select(u => new
{
fullName = u.name,
lat = u.location.Latitude,
lng = u.location.Longitude,
distance = myLocation.Distance(u.location)
}).ToList();
Run Code Online (Sandbox Code Playgroud)
响应
,{"fullName":"jons smith","lat":25.3132666,"lng":55.2994054,"distance":4133581.8647264037}
Run Code Online (Sandbox Code Playgroud)
提前致谢.