A simple library that allows a postcode to be converted into its latitude and longitude.
This repository contains the code to:
- convert the Office for National Statistics postcode file into suitable data files.
- lookup a given postcode to provide its latitude & longitude.
No databases, just files.
git clone https://github.com/glynnbird/postcodelookup.git
cd postcodelookup
npm install
Download the latest postcode lookup data from the Office for National Statistics.
Unzip the download and look in the directory structure for a large CSV file e.g. NSPL_FEB_2020_UK/Data/NSPL_FEB_2020_UK.csv
- we need this file for our setup process.
Run setup.js
passing in the path to that CSV file to do a one-off setup process e.g:
./setup.js ~/Downloads/NSPL_FEB_2020_UK/Data/NSPL_FEB_2020_UK.csv
In your code:
const lookup = require('.')
lookup('w1a1aa')
// { pc: 'W1A 1AA', lat: '51.518561', long: '-0.143799' }