我需要计算英国邮政编码之间的距离。 我不想使用web api。 为此存在一个python模块/库吗? 或者我必须使用OrdnanceSurvey的数据来组合我自己的东西吗?英国邮政编码之间距离的Python模块
感谢,
我需要计算英国邮政编码之间的距离。 我不想使用web api。 为此存在一个python模块/库吗? 或者我必须使用OrdnanceSurvey的数据来组合我自己的东西吗?英国邮政编码之间距离的Python模块
感谢,
1 /你可以使用任何其他地理位置API如谷歌地图,这将提供您基于该pincodes精确的距离。
2 /您可以使用任何具有邮政编码和纬度/经度信息的更新数据库,并使用该信息计算两点之间的距离。
帮助链接:
我)http://blog.acmultimedia.co.uk/2008/03/uk-post-code-distance-calculator-using-phpmysql/
II)Django - how can I find the distance between two locations?
请参阅下面的简单代码,使用postcodes module作为python以及google maps distance matrix API。
from postcodes import PostCoder
import requests
import json
import pprint
pc = PostCoder()
origin_postcode = str.upper(raw_input("Enter origin PostCode:"))
dest_postcode = str.upper(raw_input("Enter destination PostCode:"))
origin = str(pc.get('%s' % origin_postcode)['geo']['lat'])+','+str(pc.get('%s' % origin_postcode)['geo']['lng'])
dest = str(pc.get('%s' % dest_postcode)['geo']['lat'])+','+str(pc.get('%s' % dest_postcode)['geo']['lng'])
data = requests.get('https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=%s&destinations=%s&key=AIzaSyDfTip2PrdaRkF1muCLP8REAk3FsLjmBrU' % (origin, dest))
new = json.loads(data.text)
miles = str(new['rows'][0]['elements'][0]['distance']['text']).replace('mi','miles')
duration = str((new['rows'][0]['elements'][0]['duration']['text']))
print '\n\nThe distance from %s to %s is %s, taking approximately %s (driving).' % (origin_postcode, dest_postcode, miles, duration)
postcodes似乎不适合我(python 3.5) – famargar 2017-05-19 14:55:07
谢谢。我编辑了这个问题,说我不想使用web api。是的,我正在考虑使用选项2,但想知道是否有一个现有的模块,只是为我做了这个,而不需要我自己一起破解它。 – 2012-04-10 10:21:11
第一个链接似乎中断 – famargar 2017-05-19 14:55:53