如何计算Google地图V3中两个标记之间的距离?(类似于distanceFromV2中的功能.)
谢谢..
我需要一个函数来计算A点和B点之间的距离.
命名空间System.Spatial似乎正是我需要的,但我无法想象如何使用它.
IPoint是一个提供Latitude和Longitude两种类型的接口double.
第一次尝试 :
public static double CalculateDistance(IPoint pointA, IPoint pointB)
{
var gp1 = GeographyPoint.Create(pointA.Latitude, pointA.Longitude);
var gp2 = GeographyPoint.Create(pointB.Latitude, pointB.Longitude);
return gp1.Distance(gp2) ?? 0;
}
Run Code Online (Sandbox Code Playgroud)
以A结尾NotImplementedException的point1.Distance(point2).该消息是法语,但基本上它说"没有注册操作.请使用属性SpatialImplementation.CurrentImplementation.Operations提供操作".
好的,我会试试这个:
public static double CalculateDistance(IPoint pointA, IPoint pointB)
{
var gp1 = GeographyPoint.Create(pointA.Latitude, pointA.Longitude);
var gp2 = GeographyPoint.Create(pointB.Latitude, pointB.Longitude);
return SpatialImplementation.CurrentImplementation.Operations.Distance(gp1, gp2);
}
Run Code Online (Sandbox Code Playgroud)
现在,我得到了一个NullReferenceException上SpatialImplementation.CurrentImplementation.Operations.
Msdn对此并不是很冗长.
任何人都可以解释如何获得这些实现?
我可以使用以下SQL来计算固定位置与数据库中场地的位置之间的距离.
SELECT Location.STDistance(geography::Point(51, -2, 4326)) * 0.00062137119 FROM Venues
Run Code Online (Sandbox Code Playgroud)
请注意,返回的距离以英里为单位,位置字段是地理类型.
我想知道在.NET中它的等价物会返回相同的值.此方法将具有以下签名:
public static double Distance(location1Latitude, location1Longitude, location2Latitude, location2Longitude) {
return ...;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以在.NET中调用数据库方法,但我不希望这样做.我希望有一个计算距离的公式.谢谢