[英]DbGeography.Distance returned incorrect result
这是我的简化代码:
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);
这是“CreatePoint”function:
public static DbGeography CreatePoint(decimal Longitude, decimal Latitude)
{
return DbGeography.FromText(String.Format(CultureInfo.InvariantCulture, "POINT({0} {1})", Longitude, Latitude));
}
我在几个来源中看到结果应该以米为单位,所以我预计会看到493 :
http://boulter.com/gps/distance/?from=-73.98%2C40.7155773&to=-73.984434%2C40.7155773&units=k
谷歌地图测量工具显示相同的结果(但它不允许共享链接)。
但是我从“距离” function 得到的结果是374.65 。 我检查了两个对象的 CoordinateSystemId,它的默认值是 4326。
那么我做错了什么? 或者那个结果是哪个单位的?
检查纬度/经度顺序是否在某处交换。
如果我在您的 boulter 链接中交换订单,我会得到 0.37k: http://boulter.com/gps/distance/?from=40.7155773%2C-73.98&to=40.7155773%2C-73.984434&units=k这可能就是您得到的在 C# 代码中。
请注意,博尔特和谷歌地图的顺序应该是latitude, longitude
; WKT 使用相反顺序的longitude, latitude
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.