Class 5 in-class exercise solution

Class 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': 4230080,
  '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.6347211541681101,
  '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'