#!/usr/bin/python3 # ==================================================================== # geocoding / geolocation # ==================================================================== import sys import json import requests import urllib ##location = 'altadena, CA, 91001' location = 'Pasadena, CA' url = 'https://nominatim.openstreetmap.org/search/' + \ urllib.parse.quote(location) + '?format=json' ##print() ##print(url) ##print() response = requests.get(url).json() print(f'response type={type(response)} len={len(response)}') if len(response) < 0: print('no information found for {location}') sys.exit() for r in response: print() print(f'place_id: {r["place_id"]}') print(f'lat : {r["lat"]}') print(f'lon : {r["lon"]}')