I need to create a JavaScript database of shops that will sort by the user's specified postcode. The limitations are that this needs to run entirely in the browser. After the user has input their postcode, I need to display a list of the nearest first, displaying the shop name, town, county, and distance in miles, with a link to another page for more details.
I have thought of displaying every shop on a google map and somehow using it to calculate the distance between the user postcode and the nearest shop, though not sure if this is possible?
I have also thought of using TaffyDB to create the in-browser database:
var shops = TAFFY([{
name: "Spaday",
town: "Canterbury",
county: "Kent",
postcode: "CT1 1FG"
}, {
name: "BodySan",
town: "Southend-on-Sea",
county: "Essex",
postcode: "SS1 1PG"
}]);
But the crucial point is that I have no idea how to implement the postcode sort, would be ideal if the user could also sort within a specified range e.g. 10 miles etc. I do not need extreme distance accuracy but the more accurate the better.
What would be the best way to sort the shops by postcode in the browser? And might there be a better way of creating this in-browser shop database?
Any help would be greatly appreciated.