0

I am doing a project and am having trouble, I would like to know if there is a way to find the distance between two postcodes in python, to the nearest mile. I have searched for ages and haven't stumbled across a solution I would like it if either someone could point me in the right direction.

I would like it so that when I put two postcodes into python it will output how far they are in miles from each other. I have tried to implement a map to show the distances in tkinter but this proved to me massively difficult so I have had to refrain from doing this and had to just make it show the distance

martineau
  • 119,623
  • 25
  • 170
  • 301
  • https://pypi.org/project/uszipcode/ this should help, try the long,lat and see if you can figure out how to convert difference of long,lat to miles. – Aiden Zhao Mar 19 '19 at 21:08
  • here shows how to calculate distance https://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points – Aiden Zhao Mar 19 '19 at 21:16

1 Answers1

2

https://postcodes.io/ - service for getting various postcode info. You can use existing instance or you can spin up your own, it's free.

Service above gives you latitude and longitude for the specified postcode. Having two postcodes gives you two points and their lat and long.

Having coordinates of two points makes it possible to define distance between these points. ( be aware that this formula ignores obstacles between points e.g. mountains. )

distance by coordinates - here is the formula.

For more precise distance you can use google API. It's not free.

API - google distance API.

Ivan Lymar
  • 2,180
  • 11
  • 26