Library to calculate distances between postcodes in the UK

只愿长相守 提交于 2019-12-02 17:14:44

问题


I am looking for a way to calculate approximate distance between two UK postcodes (distance in the straight line is good enough) for analysing data. Preferably easily accessible from java, but C#, native C++ etc. are fine as well.


回答1:


First, you need to translate the postcode into useful coordinates. For example, the Easting and Northing values from a Postcode lookup table, like the one from here: http://www.doogal.co.uk/UKPostcodes.php

These Easting and Northing are UK Ordnance Survey grid coordinates in metres from the OS map origin.

Convert them into Kilometres by dividing by 1000

Then use a simple Pythagoros triangle formula. Say the two points have Easting and Northing values (in kilometres) of E1, N1 and E2, N2

Distance between them in Kilometres = Square root of ( abs(E1-E2)^2 + abs(N1-M2)^2 )




回答2:


The following question answers the exact same question only in PHP specifically:

Using PHP and google Maps Api to work out distance between 2 post codes (UK)

It leverages a web service API though, so you should be able to use any basic rest api to leverage it (I'm sure there are well documented options in Java, C# and C++).



来源:https://stackoverflow.com/questions/8695276/library-to-calculate-distances-between-postcodes-in-the-uk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!