Created
July 31, 2017 19:18
-
-
Save didasy/74ae06a08e9669e85fc08ef976d6ccf0 to your computer and use it in GitHub Desktop.
Calculate distance between two GPS point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Calculate distance between two points | |
| float distanceCoordinates(float flat1, float flon1, float flat2, float flon2) { | |
| // Variables | |
| float dist_calc=0; | |
| float dist_calc2=0; | |
| float diflat=0; | |
| float diflon=0; | |
| // Calculations | |
| diflat = radians(flat2-flat1); | |
| flat1 = radians(flat1); | |
| flat2 = radians(flat2); | |
| diflon = radians((flon2)-(flon1)); | |
| dist_calc = (sin(diflat/2.0)*sin(diflat/2.0)); | |
| dist_calc2 = cos(flat1); | |
| dist_calc2*=cos(flat2); | |
| dist_calc2*=sin(diflon/2.0); | |
| dist_calc2*=sin(diflon/2.0); | |
| dist_calc +=dist_calc2; | |
| dist_calc=(2*atan2(sqrt(dist_calc),sqrt(1.0-dist_calc))); | |
| dist_calc*=6371000.0; //Converting to meters | |
| return dist_calc; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment