Tags

, , , , , , , , , , ,

Web has changed a lot in last few years. Few years ago, distance calculation was needed only in aeronautic science. But that is now required in normal web sites.  So I thought I would write down steps to find out distance between 2 points in simple words here. Hope this could be helpful for someone. And if not, at-least this post can be a reference for myself.

Here is a sample workaround to Find distance between Avinguda Gabriel Roca, 54, 07015 Palma (Mallorca), Spain  AND Avenida de Juan Miró, 174, 07015 Palma, Spain

HERE WE GO -

Requirement: Find distance between distance_from  and distance_till

distance_from =  39°33’1.89″N,   2°37’25.21″E (Avinguda Gabriel Roca, 54, 07015 Palma (Mallorca), Spain)
distance_till =  39°33’12.79″N,    2°37’21.44″E (Avenida de Juan Miró, 174, 07015 Palma, Spain)

Solution:
As per Annexure-I lat and long will be +ve number
distance_from = 39+(33/60.0)+(1.89/3600.0), 2+(37/60.0)+(25.21/3600.0)
distance_till = 39+(33/60.0)+(12.79/3600.0),  2+(37/60.0)+(21.44/3600.0)

As per Annexure-II
lat1 = 39.550525
lon1 = 2.623669
lat2 = 39.553553
lon2 = 2.622622

As per Annexure-III (result of this formula is in KM)
SELECT (6371 * ACOS(SIN(RADIANS( 39.550525 )) * SIN(RADIANS( 39.553553 )) + COS(RADIANS( 39.550525 )) * COS(RADIANS( 39.553553 )) * COS(RADIANS( 2.622622 ) – RADIANS( 2.623669 )))); => 0.348458973417713 KM

Thats it ! Enjoy !

Annexure-I
POS. LATITUDE = NORTH
NEG. LATITUDE = SOUTH
POS. LONGITUDE = EAST
NEG. LONGITUDE = WEST
i.e NORTH / EAST => +ve & SOUTH/WEST => -ve

Annexure-II
Decimal value = Degrees + (Minutes/60) + (Seconds/3600)

Annexure-III
select (6371 * ACOS(SIN(RADIANS( %lat1% )) * SIN(RADIANS( %lat2% )) + COS(RADIANS( %lat1% )) * COS(RADIANS( %lat2% )) * COS(RADIANS( %lon2% ) – RADIANS( %lon1% )))) as distance_in_km;

Advertisement