如何对服务器上的地址进行地理编码 [英] How to geocode addresses on the server
问题描述
我正在使用python使用Google App Engine编写应用程序,并且将一个大的维基百科列表转换为电子表格,然后将列表行输入到位置"中.例如: http://en.wikipedia.org/wiki/List_of_North_Carolina_state_parks ,我需要把每个公园的名字变成一个地址,我想他们不会是确切的,但是只要他们几乎是正确的,对我来说就可以了.
I am writing an app with Google App Engine using python and I am turning a large wikipedia list into a spreadsheet and then inputting the list rows into Locations. For example this: http://en.wikipedia.org/wiki/List_of_North_Carolina_state_parks and I need to turn the name of each park into an address, I would imagine they won't be exact but as long as they are almost correct it is alright with me.
有什么办法可以在服务器端使用python做到这一点?我知道Google的地址编码服务,但这全是用javascript完成的,并且它的速率受到限制.
Is there any way I can do this using python on the server side? I know about Google's Geocoding service but it is all done with javascript and it is rate limited.
有没有可以做到这一点的服务?
Is there any service that can do this?
更新: geopy正是我想要的.我想知道处理多个结果的最佳方法是什么.这是我的尝试:
UPDATE: geopy is just what I was looking for. I am wondering what the best way to deal with multiple results is. Here is my attempt:
try:
place, (lat, lng) = g.geocode(title+", North Carolina")
except ValueError:
geocodespot = g.geocode(title+", North Carolina", exactly_one=False)
place, (lat, lng) = geocodespot[0]
它工作得很好,但是我想知道是否还有更好的主意.
It works just fine but I am wondering if there are any better ideas.
推荐答案
有 geopy
库.
示例(来自入门页面):
from geopy import geocoders
g = geocoders.Google()
place, (lat, lng) = g.geocode("10900 Euclid Ave in Cleveland")
print "%s: %.5f, %.5f" % (place, lat, lng)
10900 Euclid Ave, Cleveland, OH 44106, USA: 41.50489, -81.61027
这篇关于如何对服务器上的地址进行地理编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!