SHOW:
|
|
- or go back to the newest paste.
| 1 | Global $fLocation1[2], $fLocation2[2] | |
| 2 | ||
| 3 | ;~ Location 1 | |
| 4 | $fLocation1[0] = 52.918862 | |
| 5 | $fLocation1[1] = -1.474920 | |
| 6 | ||
| 7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 8 | ||
| 9 | ;~ Location 2 | |
| 10 | $fLocation2[0] = 53.519629 | |
| 11 | $fLocation2[1] = -1.129435 | |
| 12 | ||
| 13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 14 | ||
| 15 | ||
| 16 | $fDistance = Distance($fLocation1[0], $fLocation1[1], $fLocation2[0], $fLocation2[1]) | |
| 17 | ||
| 18 | MsgBox(0,0, $fDistance) | |
| 19 | ||
| 20 | ||
| 21 | Func Distance($_Lat1, $_Lon1, $_Lat2, $_Lon2) ; I translated this from a javascript recommendation. | |
| 22 | Local $RadiusOfEarth = 6371.008 ;6371 is the volumetric mean average radius of earth. | |
| 23 | ||
| 24 | Local $_dLat = Deg2Rad($_Lat2 - $_Lat1) ; No clue... | |
| 25 | Local $_dLon = Deg2Rad($_Lon2 - $_Lon1) ; No clue... | |
| 26 | ||
| 27 | Local $_a = (Sin($_dLat / 2) * Sin($_dLat / 2)) + (Cos(Deg2Rad($_Lat1)) * Cos(Deg2Rad($_Lat2))) * _ ; No clue... | |
| 28 | (Sin($_dLon / 2) * Sin($_dLon / 2)) ; No clue... | |
| 29 | ||
| 30 | Local $_C = 2 * ATan2(Sqrt($_a), Sqrt(1 - $_a)) ; No clue... | |
| 31 | ||
| 32 | Local $_d = $RadiusOfEarth * $_C ; No clue... | |
| 33 | ||
| 34 | Return Round(($_d * 1000) * 0.000621371192237, 3) ; I added this to convert meters to miles and returns this figure to the caller, rounded to 3 decimal places. | |
| 35 | EndFunc ;==>Distance | |
| 36 | ||
| 37 | Func Deg2Rad($_input) ; I translated this from a javascript recommendation (There was no such function in AutoIt, so I had to search for one) | |
| 38 | Local $Pi = 3.1415926535897932384626433832795 | |
| 39 | Return $_input * $Pi / 180 | |
| 40 | EndFunc ;==>Deg2Rad | |
| 41 | ||
| 42 | ||
| 43 | Func ATan2($y, $x) ; Taken from the AutoIt forum, where someone else needed the ATan2 function. This was the best, fastest option of the two provided. | |
| 44 | Return (2 * ATan($y / ($x + Sqrt($x * $x + $y * $y)))) | |
| 45 | EndFunc ;==>ATan2 |