Finding Distance between Two Points Given in Latitude and Longitude Points

In many application especially in GIS system it requires to find distance between two points given latitude and longitude. Here I’m explaining the procedure to find distance from such type of points.

At First, Let Us See How a Point is Represented:
A point P is given in the format P(40°44′55″N, 73°59′11″W ). The first part is called latitude and the last part is called longitude.  We read a latitude/longitude [e.g.] 40°44′55″N as 40 degree 44 minute and 55 second North[N=North, S=South and so on E and W].

There has many formulas to find distance from given latitude and longitude points. Among them two formulas are very easy to implement and give result with a very little error. One is Haversine and another is Spherical Low of Cosine.

Keep It Mind:
The above formulas are for spheroidal shape. The earth is not quite a sphere, there are small errors in using spherical geometry; the earth is oblate spheroidal with a radius varying between about 6,378km (equatorial) and 6,357km (polar), and local radius of curvature varying from 6,336km (equatorial meridian) to 6,399km (polar). 6,371 km is the generally accepted value for the Earth’s mean radius. This means that errors from assuming spherical geometry might be up to 0.55% crossing the equator, though generally below 0.3%, depending on latitude and direction of travel. AND both the formula find shortest distance on earth surface [as-the-crow-flies]. One can use Vincenty formula for accuracy up to 1mm

If P1(lat1, long1) and P2(lat2, long2) are two given points, R is radius of the Earth and D is the distance between the points then
D=C*R, Where
C = 2*atan2(√a, √(1−a)),
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1)*cos(lat2)*sin²(Δlong/2)

Here atan2(y,x) is a special implementation of arctangent atan(y/x) in programming languages.

Spherical Low of Cosine:
For the same two points and same assumption the distance D is
D = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(Δlong))*R
The Spherical Low of Cosine gives more computational precision and finds distance as small as 1m.

Please Note That:
Depending on the calculation of trigonometric function you are required to convert the latitude and longitude into radian unit.  So if we convert the point P(40°44′55″N, 73°59′11″W ) into radiance then,
Latitude = ( (40 + 44/60 + 55/(60*60) )/180 ) and
Longitude =( (73 + 59/60 + 11/(60*60) )/180)

Then depending on the unit of R the distance D will be in km/miles/…

When a latitude/longitude will have S/W direction then put the negative(-ve) value of the latitude/longitude into those formula.

So let start to compute distance between tow points given in latitude and longitude.


One thought on “Finding Distance between Two Points Given in Latitude and Longitude Points

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s