[英]DbGeography.Distance returned incorrect result
Here is my simplified code:这是我的简化代码:
var P1 = Common.Geography.CreatePoint((decimal)-73.980000, (decimal)40.7155773);
var P2 = Common.Geography.CreatePoint((decimal)-73.984434, (decimal)40.7155773);
var Distance = P1.Distance(P2);
Here is "CreatePoint" function:这是“CreatePoint”function:
public static DbGeography CreatePoint(decimal Longitude, decimal Latitude)
{
return DbGeography.FromText(String.Format(CultureInfo.InvariantCulture, "POINT({0} {1})", Longitude, Latitude));
}
I saw in a several sources that results should be in meters so I expected to see 493 :我在几个来源中看到结果应该以米为单位,所以我预计会看到493 :
http://boulter.com/gps/distance/?from=-73.98%2C40.7155773&to=-73.984434%2C40.7155773&units=k http://boulter.com/gps/distance/?from=-73.98%2C40.7155773&to=-73.984434%2C40.7155773&units=k
Google Maps measure tool shows same result (but it doesn't allow to share link).谷歌地图测量工具显示相同的结果(但它不允许共享链接)。
However result I got from "Distance" function is 374.65 .但是我从“距离” function 得到的结果是374.65 。 I checked CoordinateSystemId for both objecs and it has default value 4326.
我检查了两个对象的 CoordinateSystemId,它的默认值是 4326。
So what I'm doing wrong?那么我做错了什么? Or in which units is that result?
或者那个结果是哪个单位的?
Check if the latitude / longitude order is swapped somewhere.检查纬度/经度顺序是否在某处交换。
I get 0.37k if I swap the order in your boulter link: http://boulter.com/gps/distance/?from=40.7155773%2C-73.98&to=40.7155773%2C-73.984434&units=k which is probably what you get in C# code.如果我在您的 boulter 链接中交换订单,我会得到 0.37k: http://boulter.com/gps/distance/?from=40.7155773%2C-73.98&to=40.7155773%2C-73.984434&units=k这可能就是您得到的在 C# 代码中。
Note that for boulter and google maps order should be latitude, longitude
;请注意,博尔特和谷歌地图的顺序应该是
latitude, longitude
; WKT uses the opposite order longitude, latitude
. WKT 使用相反顺序的
longitude, latitude
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.