Move geocoding to Google API

This commit is contained in:
Arne Schlüter 2015-01-17 19:12:09 +01:00
commit cb0175a7b7
4 changed files with 57 additions and 22 deletions

View file

@ -96,8 +96,28 @@ def get_categories(article_body):
return found_categories or ['other']
def get_geoloc(query):
encoded_query = urlencode(query + ", Berlin")
url = "http://nominatim.openstreetmap.org/search?q=" + encoded_query + " + "&countrycodes=de&format=json&limit=1"
r = requests.get(url)
confidence_map = {
"ROOFTOP": 10,
"RANGE_INTERPOLATED": 7,
"GEOMETRIC_CENTER": 4,
"APPROXIMATE": 1
}
return(r.json()[0]["lat"], r.json()[0]["lon"])
params = {
"address": query + ", Berlin",
"components": "country:DE"
}
url = "http://maps.googleapis.com/maps/api/geocode/json?" + urlencode(params)
r = requests.get(url).json()["results"]
locations = []
for location in r:
print(location)
locations.append({
"lat": location["geometry"]["location"]["lat"],
"lng": location["geometry"]["location"]["lng"],
"confidence": confidence_map[location["geometry"]["location_type"]]
})
return locations