相关疑难解决方法(0)

计算谷歌地图V3中两点之间的距离

如何计算Google地图V3中两个标记之间的距离?(类似于distanceFromV2中的功能.)

谢谢..

javascript google-maps-api-3

314
推荐指数
9
解决办法
38万
查看次数

如何使用System.Spatial.GeographyPoint

我需要一个函数来计算A点和B点之间的距离.

命名空间System.Spatial似乎正是我需要的,但我无法想象如何使用它.

IPoint是一个提供LatitudeLongitude两种类型的接口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结尾NotImplementedExceptionpoint1.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)

现在,我得到了一个NullReferenceExceptionSpatialImplementation.CurrentImplementation.Operations.

Msdn对此并不是很冗长.

任何人都可以解释如何获得这些实现?

c# geography

7
推荐指数
1
解决办法
6441
查看次数

.NET等效的SQL Server STDistance

我可以使用以下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中调用数据库方法,但我不希望这样做.我希望有一个计算距离的公式.谢谢

.net c# sql-server sqlgeography geographic-distance

4
推荐指数
1
解决办法
2079
查看次数