Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql dbgeography距离计算的错误计算_Sql_Sql Server_Azure_Azure Sql Database - Fatal编程技术网

Sql dbgeography距离计算的错误计算

Sql dbgeography距离计算的错误计算,sql,sql-server,azure,azure-sql-database,Sql,Sql Server,Azure,Azure Sql Database,我正在将EF与MSSQL DB一起使用,我正在努力进行空间查询: 我正在使用用户位置搜索按距离订购的餐厅代码如下: DbGeography userLocation = DbGeography.FromText(userLocationWKT, 4326); return (from branch in DbContext.Branches let distance = userLocation.Distance(branch.Lo

我正在将EF与MSSQL DB一起使用,我正在努力进行空间查询: 我正在使用用户位置搜索按距离订购的餐厅代码如下:

DbGeography userLocation = DbGeography.FromText(userLocationWKT, 4326);
            return (from branch in DbContext.Branches
                    let distance = userLocation.Distance(branch.Location)
                    orderby distance ascending
                    where branch.Name.ToLower().Contains(searchString.ToLower()) && branch.Location != null
                    select new BranchAndDistance { Branch = branch, Distance = distance }).ToList();
用户位置WKT为点32.78786115814 35.0162102747709。在我的测试用例中,我发送了一个查询,返回一个Lat=32.1300848&Long=34.7919443的餐厅,但是我得到的距离是370237米,这是非常遥远的

下图显示了餐厅位置详细信息的QuickWatch窗口: 请注意,在ProviderValue文本中,它显示了点34.7919443 32.1300848,好像它替换了Lat和Long,但实际值似乎正常 因此,我进行了更多的测试,因为我将lat和long值保存在单独的变量中,所以我可以测试以下内容:

double? distance = Branch.Location.Distance(userLocation);
DbGeography branchLocation = DbGeography.FromText(string.Format("POINT ({0} {1})",
                                Branch.Latitude,.Branch.Longitude), 4326);
double? distance2 = branchLocation.Distance(userLocation);
距离变量具有相同的错误距离值370237.85926851362 但distance2 variabel的正确距离值为65061.945208184392 这怎么可能? 我还检查了SQL Azure数据库管理,根据该管理,产生错误距离结果的Location属性是spot-on


我错过什么了吗?我做错了什么?

你对用户的WKT不是你想象的那样。具体来说,这是一个纬度为35.0162102747709,经度为32.78786115814的点。这里有一个小T-SQL来说明:

DECLARE @g geography;
SELECT @g = geography::STPointFromText('POINT (32.78786115814 35.0162102747709)', 4326);

SELECT @g.Lat, @g.Long;

所以你的意思是,我混合了坐标,第一个值实际上是经度,而另一个是纬度?事实上,我读到了关于WKT的文章,可能遗漏了什么。试着换个角度,看看结果是否更像你期望的那样。