Update geocoder query to send user agent
This commit is contained in:
parent
c77e8877f0
commit
da0b9f038a
|
@ -13,8 +13,13 @@
|
|||
# You will need to use these functions, but you don't need to edit this file.
|
||||
|
||||
import geocoder
|
||||
from geocoder.osm import OsmQuery
|
||||
import requests
|
||||
|
||||
class OsmQueryWithHeaders(OsmQuery):
|
||||
def _build_headers(self, provider_key, **kwargs):
|
||||
return {"User-Agent": "Making With Code CS Curriculum"}
|
||||
|
||||
def geocode_location(location_string):
|
||||
"""Translates a location string into latitude and longitude coordinates.
|
||||
Uses the OpenStreetMap API. Returns a dict with keys 'lat' and 'lng'
|
||||
|
@ -23,7 +28,7 @@ def geocode_location(location_string):
|
|||
>>> geocode_location('11 Wall Street, New York')
|
||||
{"lat": -74.010865, "lng": 40.7071407}
|
||||
"""
|
||||
result = geocoder.osm(location_string)
|
||||
result = OsmQueryWithHeaders(location_string)
|
||||
if result:
|
||||
lat, lng = result.latlng
|
||||
return {'lat': lat, 'lng': lng}
|
||||
|
|
Loading…
Reference in New Issue