How to geocode addresses on the server

2019-07-08 02:03发布

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.

2条回答
老娘就宠你
2楼-- · 2019-07-08 02:21

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?

查看更多
Viruses.
3楼-- · 2019-07-08 02:23

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  
查看更多
登录 后发表回答