Friends, I am working on something to find out distance between two latitude and longitude points.
Below is my python code, to get the distance in KM
from math import radians, cos, sin, asin, sqrt
def distance(lat1, lng1, lat2, lng2):
R = 6371 # radius of the earth in km
lng1, lat1, lng2, lat2 = map(radians, [lng1, lat1, lng2, lat2])
x = (lng2 - lng1) * cos( 0.5*(lat2+lat1) )
y = lat2 - lat1
d = R * sqrt( x*x + y*y )
return d
distance(25.42684996,81.84835984,25.45328992,81.86906992)
**Out[77]: 3.6011256577543027**
The answer is 3.60.. km. But when i cross check in google maps it says 609 km. Can any one suggest what is the mistake here?
i referred HERE and other links too
Its absolutely fine, if you have "R" - code !!!
Also, is there any way that i can find out shortest route that google proposes, in python?