Geo coding with API providers (here, radar)

Geo coding

https://radar.com/ (among many others) provides a free API (100k calls) to encode an address or a location string into precise geolocation information such as latitude/longitude pairs.

import requests

api_url = 'https://api.radar.io/v1/geocode/forward?query=841+broadway%2C+new+york%2C+ny&layers=address'
headers = {'Authorization': 'prj_test_pk_39c4e1777b3467341e57341d40d9b7794cd93660'} 

req = requests.get(api_url, headers=headers)
req
<Response [200]>
req.content
b'{"meta":{"code":200},"addresses":[{"addressLabel":"841 Broadway","number":"841","street":"Broadway","city":"New York","stateCode":"NY","postalCode":"10003","county":"New York","countryCode":"US","formattedAddress":"841 Broadway, New York, NY 10003 US","layer":"address","latitude":40.734293607,"longitude":-73.991043025,"geometry":{"type":"Point","coordinates":[-73.991043025,40.734293607]},"distance":5572.482785708698,"confidence":"exact","state":"New York","country":"United States","countryFlag":"\xf0\x9f\x87\xba\xf0\x9f\x87\xb8"}]}'
req.json()
{'meta': {'code': 200},
 'addresses': [{'addressLabel': '841 Broadway',
   'number': '841',
   'street': 'Broadway',
   'city': 'New York',
   'stateCode': 'NY',
   'postalCode': '10003',
   'county': 'New York',
   'countryCode': 'US',
   'formattedAddress': '841 Broadway, New York, NY 10003 US',
   'layer': 'address',
   'latitude': 40.734293607,
   'longitude': -73.991043025,
   'geometry': {'type': 'Point', 'coordinates': [-73.991043025, 40.734293607]},
   'distance': 5572.482785708698,
   'confidence': 'exact',
   'state': 'New York',
   'country': 'United States',
   'countryFlag': '🇺🇸'}]}
req.json()['addresses'][0]['latitude']
40.734293607
req.json()['addresses'][0]['longitude']
-73.991043025