2012-04-10 80 views

回答

1

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?

+0

谢谢。我编辑了这个问题,说我不想使用web api。是的,我正在考虑使用选项2,但想知道是否有一个现有的模块,只是为我做了这个,而不需要我自己一起破解它。 – 2012-04-10 10:21:11

+0

第一个链接似乎中断 – famargar 2017-05-19 14:55:53

1

我不知道直接使用模块的,但是你可以使用GRASSQGIS,这两者都支持Python脚本所以这个功能可以用作python模块。尽管如此,你仍然需要弄清楚如何在这些工具中手动完成它,但这并不是非常困难。

+0

谢谢队友!我想我将使用此处列出的所有资源创建一个模块。 – 2012-04-10 12:44:18

0

请参阅下面的简单代码,使用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) 
+0

postcodes似乎不适合我(python 3.5) – famargar 2017-05-19 14:55:07

相关问题