小编Muz*_*ain的帖子

SQL Server Geography与DbGeography

我有两个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)

以上sql查询的结果

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)

提前致谢.

.net c# sql-server entity-framework geospatial

8
推荐指数
1
解决办法
1283
查看次数

标签 统计

.net ×1

c# ×1

entity-framework ×1

geospatial ×1

sql-server ×1