I need a function to calculate the distance between point A and point B.
The System.Spatial seems to be exactly what I need, but I cannot figure out how to use it.
IPoint is the interface that Latitude and Longitude provide, both of double types.
First try:
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; }
This ends with a NotImplementedException at point1.Distance(point2) . The message is in French, but basically it says: "No operation is registered. Provide the operation using the SpatialImplementation.CurrentImplementation.Operations property."
Ok, I will try this:
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); }
Now I got a NullReferenceException on SpatialImplementation.CurrentImplementation.Operations .
Msdn not many details.
Can anyone explain how to get these implementations?
source share