Python/C API extension module that computes distance between two coordinates on the world map.
As more and more apps are using maps, the more demand for geolocation capabilities increase. Geolocation is about the reporting of your location to other users, as well as associating real-world locations (such as landmarks) to your location. This repo helps to accurately calculate the distance between two locations and presents a time efficient practical solution, that is almost 3 times faster than similar fast pure python implementation.
python setup.py install
Or using alternative command:
pip install https://github.com/duboviy/dist/archive/master.zip
The dist function accepts four float parameters:
- lat1, lon1: The Latitude and Longitude of point 1 (in decimal degrees)
- lat2, lon2: The Latitude and Longitude of point 2 (in decimal degrees)
The unit of measurement in which result is calculated is kilometers. [float]
>>> import dist
>>> dist.compute(10.1, 12.1, 10.1, 10.1)
218.933532715
This Python/C API Extension module is in ~ 3 times faster than similar fast pure python implementation. You can use performance test to compare speed with fast pure python implementation, just run nose test runner:
>>> nosetests
ext_time: 2.46785402298 pure_py_time: 7.49713611603
Checked under following Python versions:
- 2.6
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
Module accounts the curvature of the Earth when calculating large distances on the world map. If the Earth were flat, calculating the distance between two points would be very simple as for a straight line. The Haversine formula is used in current implementation, it includes a constant that represents the radius of the Earth. The Haversine formula is not 100% accurate because the Earth is not a perfect sphere. However, the Haversine gives a good enough approximation for most applications that use geolocation.
MIT licensed library. See LICENSE.txt for details.
If you have suggestions for improving the dist, please open an issue or pull request on GitHub.