Download UK Postcodes with Latitude and Longitude
https://www.freemaptools.com/download-uk-postcode-lat-lng.htm
https://github.com/dwyl/uk-postcodes-latitude-longitude-complete-csv
php script
https://www.hashbangcode.com/article/converting-uk-postcode-longitude-and-latitude-php
Calculating distance
https://www.geodatasource.com/developers/php
https://martech.zone/calculate-distance/
SQL: Retrieving All Records Within A Range By Calculating Distance In Miles Using Latitude and Longitude
It’s also possible to use SQL to do a calculation to find all records within a specific distance. In this example, I’m going to query MyTable in MySQL to find all the records that are less than or equal to variable $distance (in Miles) to my location at $latitude and $longitude:
The query for retrieving all of the records within a specific distance by calculating distance in miles between two points of latitude and longitude are:
$query = "SELECT *, (((acos(sin((".$latitude."*pi()/180)) * sin((`latitude`*pi()/180)) + cos((".$latitude."*pi()/180)) * cos((`latitude`*pi()/180)) * cos(((".$longitude."- `longitude`)*pi()/180)))) * 180/pi()) * 60 * 1.1515) as distance FROM `table` WHERE distance <= ".$distance."