Search code examples
pythonpandasapicsvlatitude-longitude

Newyork BBL to Latitude/Longitude API


I want to convert NewYork BBL numbers to Latitude Longitude values. The BBL values are present as CSV file. Is there a Free API to convert them using python?


Solution

  • These has one month free.. If you go an sign up for a free account, this code works (I tried it out).

    import pandas as pd
    import requests
    
    TOKEN = 'YOUR TOKEN'
    
    def get_coord(bbl):
        url = f'https://locatenyc.io/arcgis/rest/services/locateNYC/v1/GeocodeServer/findAddressCandidates?singleLine={bbl}&token={TOKEN}'
        resp = requests.get(url)
        data = resp.json()
        attrs = data['candidates'][0]['attributes']
        return attrs['longitudeInternalLabel'], attrs['latitudeInternalLabel']
    
    df['coords'] = df['bbl'].apply(get_coord)