Code snippet Using AutoIt to calculate distance between two GPS locations
techwg
Code snippet link: https://pastebin.com/raw/5JzsxTic This lets you take decimal GPS coordinates and calculate the distance between two locations. This was destined for my other channel, but due to changes in adsense requirements, that other channel is not doing me much good any more, as it's rare that I make tutorials. So I will add it here.
I translated this from a Javascript and added a couple of UDF to fill in for missing functions. I have personally used this basic calculation in a larger program that makes use of ONS postcode location data so that I can supply two postcodes to find the distance between them. It was quite difficult to make that larger program because I had to make functionalities to process the raw data and sort it to allow for faster logical locating of distances within a range I needed. But, this snippet is the raw system to get miles distance between two locations.
You could build on this as I have done.
I cannot show the larger code for my project at work but I will share the idea of it. I take the raw ONS data from here: https://geoportal.statistics.gov.uk/search?collection=Dataset&sort=-created&tags=all(PRD_NSPL%2CNOV_2023)
Then, since the data is too large to deal with one file, I use the smaller files and get the postcode without any spaces and get the coordinates. Then build my smaller list of postcodes by using this code snippet to calculate the distance between every postcode and my target location and if it's under a certain number of miles, add it to the list.
Then once I have a full list of postcodes in the range I need for my purposes, I sort them so the closest ones are first, so that it makes searching for the distance between two postcodes quicker, when they are most likely to be of relevance to my needs. Then I save the sorted results and use that to load into an array for use and searching, so that I can then supply two postcodes and get the distance by looking up the coordinates and calculating the distances.
Enjoy. ... https://www.youtube.com/watch?v=Z4-zgayf_z4
16468553 Bytes