0

What method do you recommend I use to calculate the distance between two UK postcodes to decide whether it is in range or not?

I will not be displaying a map, simply showing a list of results of valid locations. e.g. Locations within 50 miles of BT53 6EX

Enayet Hussain
  • 908
  • 4
  • 17
  • 33
  • Already answered here (PHP) amigo: http://stackoverflow.com/questions/2296087/using-php-and-google-maps-api-to-work-out-distance-between-2-post-codes-uk and here's the JS equivalent: https://developers.google.com/maps/documentation/javascript/examples/directions-waypoints?csw=1 – Tim Jun 03 '15 at 18:56
  • "Note that the server-side geocoding service may only be used in conjunction with displaying results on a Google map" I will not be displaying a map – Enayet Hussain Jun 03 '15 at 18:58
  • Let me google that for you: http://bit.ly/1Q7jVtv – Barett Jun 03 '15 at 19:03
  • @Barett you're the least helpful person I've ever had answer one of my questions. I hope to never receive any replies from you on any of my posts ever again. Thanks – Enayet Hussain Jun 03 '15 at 19:08
  • Did you try visiting any of the links? 2 are free api's to do exactly what you're looking for. http://www.uk-postcodes.com/api . http://postcodes.io mentioned below is another good one. – Barett Jun 03 '15 at 19:39

1 Answers1

0

This is just a suggestion, you don't really specify anything to answer you question in a satisfactory way.

Store latitude and longitude along postcodes and filter so that latitude AND longitude difference is within 50 miles:

SELECT * FROM postcodes WHERE ABS(latitude - @lat) < 50 AND ABS(longitude - @lng) < 50

Then filter the resulting set by computing the actual distance, because the query above would return all in a square 50 miles distance, not in a radial distance.

pid
  • 11,472
  • 6
  • 34
  • 63
  • How would I convert the postcodes I have into geographical distance? – Enayet Hussain Jun 03 '15 at 18:59
  • @EnayetHussain Ha! I supposed wrongly that you already have that data. I downloaded similar data from the Ministry of Internal Affairs (in Italy) for a system that required it (but only distances between cities). Maybe there's a database that has all that data. But as Tim suggests, that API may be way way better! listen to him please :) – pid Jun 03 '15 at 19:04