Distance measuring

Jun 24, 2010 at 8:40 PM
Hi, I am a beginner in GPS.NET 3.0. My question is - how to measure a distance between two points which are describe by latitude and longitude? Is implement any method in library to do that? Regards, Michal from Poland
Jun 25, 2010 at 2:24 PM
Edited Jun 25, 2010 at 2:27 PM

Yes, this functionality is implemented in GPS.Net. Actually, it's implemented in GeoFrameworks, which is used by GPS.Net.

The two types that you need are Position and Distance. Position represents a single point on the Earth's surface in latitude and longitude. Distance, as you can imagine, represents the distance between two points. So, assuming that you have two Position objects, you can use the DistanceTo method to get a Distance object that represents the distance between those two Positions. The best part is that the DistanceTo method automatically takes the curvature of the Earth into account, so you get an accurate three-dimensional Distance rather than a simple addition/subtraction of the lat/long values.

Here's some sample code that calculates the distance between my current location and the North Pole.

Latitude myCurrentLatitude = new Latitude(35.529049);
Longitude myCurrentLongitude = new Longitude(-97.571156);
Position myCurrentPosition = new Position(myCurrentLatitude, myCurrentLongitude);
Distance myDistanceFromTheNorthPole = myCurrentPosition.DistanceTo(Position.NorthPole);