GeoExtension

GeoExtension

Introduction

Calculate distance, bearing, mid-point between two geographical points is not an easy job. All the formula that use for calculation is based on the basis of a spherical earth and ignoring ellipsoidal effects of the earth. In fact, the earth is actually oblate spheroidal with a radius varying between 6378KM at equatorial to 6357KM at polar. Local radius of curvature from equatorial meridian to polar is 6336KM and 6399KM respectively. With all of this differences, 6371KM is the generally accepted value for the earth’s mean radius; using a spherical model for calculation will gives errors typically up to 0.3%.

Unfortunately, Geolocation API from Windows 10 or Windows Phone 8.1 does not provide any easy approach to performance the calculation to obtain the following:

  • Calculate distance between two given Geo locations.
  • Calculate bearing angle between two given Geo locations.
  • Calculate mid point location between two given Geo locations.
  • Calculate destination location by given starting Geo locations, heading and distance traveled.

As for the result, I have spend a litter bit of time based on “haversine” formula which calculate the great-circle distance between two points to produce this GeoExtension to performance the above computations, and it also provide additional features such as:

  • Convert bearing to compass direction.
  • Convert degree angle to double.

Installation

Currently you can obtain the GeoExtension from NuGet with the following command:

PM> Install-Package GeoExtensions

Usage

double distance = GeoAssist.CalculateDistanceBetweenTwoGeoPoints(Geopoint startpoint, Geopoint endpoint);

double bearing = GeoAssist.CalculateBearingFromTwoGeoPoints(Geopoint startpoint, Geopoint endpoint);

Geopoint endpoint = GeoAssist.CalculateDestinationGeoPoint(Geopoint startpoint, double distance, double heading);

Geopoint midpoint = GeoAssist.CalculateMidGeoPointBetweenTwoGeoPoints(Geopoint startpoint, Geopoint endpoint);

string direction = GeoAssist.ConvertBearingToCompassDirection(double heading);

double angleindouble = GeoAssist.ConvertDegreeAngleToDouble(double degrees, double minutes, double seconds);

GeoAngle angleindegree = GeoAngle.ConvertDecimalAngleToDegreeAngle(double angleInDegrees);

Conclusion

Feel free to leave any feedbacks and comments, so I can improve the GeoExtension

Comments are closed.