Understanding GPS Coordinates (Latitude and Longitude)

world latitude longitude map

Many of you are keen to know what is Latitude and Longitude are in a GPS coordinate. Well then you are at the right place.

Latitude and Longitude:
The Latitude and Longitude are the geometrical address of any location on earth which are measured in degrees. Our earth is divided into two angular axis known as Latitude and Longitude. As you can see in the image the vertical line shows the Latitude which goes from -90° to +90° and the horizontal line shows the Longitude which goes from -180° to +180°.
The value of the Latitude is always zero at the line of equator where as the Longitude is zero at the line of prime meridian.

Latitude and Longitude in GPS:
The GPS stands for Global Positioning System. When any GPS device like in mobile phone asks the satellite fro their current location, the satellite returns their current geometric coordinates(Latitude and Longitude) through which the GPS device recognizes its current location. Most of the GPS devices are as accurate as they changes coordinates at 1 meter.

Finding distance between two GPS coordinates (two Latitude, Longitude)
You can easily find out the distance between two GPS coordinates by using a little Trigonometry :-)
I know most of you don’t like Trigonometry/Maths. Here is the mathematical formula to calculate the distance:-

Their is a formula known as “Haversine formula” which gives the distance between the two coordinates of the sphere. This formula is very important in Navigation and is used worldwide by many people to calculate the distance between two geographical coordinates.

Haversine formula:
a = sin²(Δφ/2) + cos(φ1).cos(φ2).sin²(Δλ/2)
c = 2.arcsin(√a)
d = R.c

where:-
Δφ = difference of two Latitude in radian
Δλ = difference of two longitude in radian
φ1,φ2 are two Latitude
λ1,λ2 are tow longitude

Explanation:-

Assuming the Earth RADIUS = 6371 KM (Approx.)
Value of PIE = 22/7

LATITUDE1_IN_RADIAN = LATITUDE1 * PIE / 180
LONGITUDE1_IN_RADIAN = LONGITUDE1 * PIE / 180

LATITUDE2_IN_RADIAN = LATITUDE2 * PIE / 180
LONGITUDE2_IN_RADIAN = LONGITUDE2 * PIE / 180

LATITUDE_DIFFERENCE = LATITUDE2 – LATITUDE1
LATITUDE_DIFFERENCE_IN_RADIAN = LATITUDE_DIFFERENCE * PIE / 180

LONGITUDE_DIFFERENCE = LONGITUDE2 – LONGITUDE1
LONGITUDE_DIFFERENCE_IN_RADIAN = LONGITUDE_DIFFERENCE * PIE / 180

a = SIN(LATITUDE_DIFFERENCE_IN_RADIAN / 2) * SIN(LATITUDE_DIFFERENCE_IN_RADIAN / 2) + COS(LATITUDE1_IN_RADIAN) * COS(LATITUDE2_IN_RADIAN) * SIN(LONGITUDE_DIFFERENCE_IN_RADIAN) * SIN(LONGITUDE_DIFFERENCE_IN_RADIAN)

DISTANCE IN KMs = RADIUS * 2 * ARCSIN( SQUARE_ROOT(a) )

Function for programmers to find the distance between two Latitude and Longitude:-

 

For JavaScript:-

function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
  var R = 6371; // Approx. radius of the earth in km
  var dLat = Degee2radian(lat2-lat1);  // Degee2radian is below
  var dLon = Degee2radian(lon2-lon1); 
  var a =  Math.sin(dLat/2) * Math.sin(dLat/2) +
           Math.cos(Degee2radian(lat1)) * Math.cos(Degee2radian(lat2)) * 
           Math.sin(dLon/2) * Math.sin(dLon/2); 
  var d = R * 2 * Math.asin(Math.sqrt(a)); // Distance in km
  return d;
}

function Degee2radian(deg) {
  return deg * (Math.PI/180)
}

 

For PHP:-

function getDistanceFromLatLonInKm($lat1,$lon1,$lat2,$lon2) {
    $R = 6371; // Approx. radius of the earth in km
    $pi80 = M_PI / 180;
    $lat1 *= $pi80;
    $lon1 *= $pi80;
    $lat2 *= $pi80;
    $lon2 *= $pi80;
    $dLat = $lat2 - $lat1;
    $dLon = $lon2 - $lon1; 
    $a =  sin($dLat / 2) * sin($dLat / 2) + cos($lat1) * cos($lat2) * sin($dLon / 2) * sin($dLon / 2); 
    $d = $R * 2 * asin(sqrt(a)); // Distance in km
    return $d;
}