How to geocode addresses on the server

拥有回忆 提交于 2019-12-12 18:52:29

问题


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.

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?

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.


回答1:


There is the geopy library.

Example (from the getting started page):

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  



回答2:


Google geocode does not require any key to use.

All information about the most recent version can be found:

https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding

all you have to do is make a request to:

(example) http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false

then use urllib

import urllib
// pull lat and lng from your parks database and construct a url like:
url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false'

resp = urllib.urlopen(url)
resp.read() // json string convert to python dict

It is rate limited, But it is a free service. It is most certainly not all done with javascript. Why does it matter if it is rate limited if you are just geocoding a static list of nc parks?



来源:https://stackoverflow.com/questions/12697524/how-to-geocode-addresses-on-the-server

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