Lecture 5 in-class exercise solution

Lecture 5 in-class exercise solution#

import requests

params = {
    "q": "White House, Washington, D.C.",
    "format": "jsonv2",
}
response = requests.get(
    "https://nominatim.openstreetmap.org/search",
    params=params,
    headers={"user-agent": "Python in-class exercise"},
)
data = response.json()
data
[{'place_id': 319313672,
  'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',
  'osm_type': 'way',
  'osm_id': 238241022,
  'lat': '38.897699700000004',
  'lon': '-77.03655315',
  'category': 'office',
  'type': 'government',
  'place_rank': 30,
  'importance': 0.6863355973183977,
  'addresstype': 'office',
  'name': 'White House',
  'display_name': 'White House, 1600, Pennsylvania Avenue Northwest, Ward 2, Washington, District of Columbia, 20500, United States',
  'boundingbox': ['38.8974908', '38.8979110', '-77.0368537', '-77.0362519']}]
place = data[0]
lat = place["lat"]
lon = place["lon"]
f"Coordinates: {lat}, {lon}"
'Coordinates: 38.897699700000004, -77.03655315'