Find an address by postcode
Many forms ask for the postcode first and offer the addresses in it, the way government services and checkouts do. That usually means a paid lookup service. Here it is one route of your own server and one file of JavaScript.
New Take addresses in Server, Docker Browser Websites, help desks Public sector
What you have
The country file and a server you can run a program on. The element integrations/web/gridpin-address-finder.js is one file with no dependencies.
Steps
1. Start the server on the country file:
$ gridpin serve germany.bin --port 8080
2. Ask for a postcode and a street with the number:
$ curl -s 'http://127.0.0.1:8080/v1/addresses?postcode=10117&number=Albrechtstra%C3%9Fe%205'
{"addresses":[{"commune":"Mitte","housenumber":"5","label":"Albrechtstraße 5, 10117, Mitte","lat":52.5228552,"lon":13.3838799,"postcode":"10117","region":null,"street":"Albrechtstraße"}],"more":false}
3. Or the first addresses of a postcode:
$ curl -s 'http://127.0.0.1:8080/v1/addresses?postcode=10117&limit=3'
{"addresses":[{"commune":"Mitte","housenumber":"1","label":"Aaron-Bernstein-Platz 1, 10117, Mitte","lat":52.5253548,"lon":13.3902292,"postcode":"10117","region":null,"street":"Aaron-Bernstein-Platz"},{"commune":"Mitte","housenumber":"2","label":"Aaron-Bernstein-Platz 2, 10117, Mitte","lat":52.5251711,"lon":13.3909071,"postcode":"10117","region":null,"street":"Aaron-Bernstein-Platz"},{"commune":"Mitte","housenumber":"3","label":"Aaron-Bernstein-Platz 3, 10117, Mitte","lat":52.5250555,"lon":13.3905032,"postcode":"10117","region":null,"street":"Aaron-Bernstein-Platz"}],"more":true}
4. Put the element in your form; it calls the same route and fills the fields:
<script type="module" src="gridpin-address-finder.js"></script> <gridpin-address-finder endpoint="http://127.0.0.1:8080" name-prefix="delivery-"></gridpin-address-finder>
What you get
A list of houses with a label in the country's order, the parts for the form fields and a point. more: true means the list was cut: ask for the street or the number.
Why it works
The server walks the houses of the postcode on the country file. The element shows them as a list, announces how many were found and always offers typing the address by hand.
Limits
- One lookup takes 0.06 to 0.7 seconds: fine for a button, too slow for every key.
- Where a postcode covers many streets (Germany, Poland), ask for the street with the number.
- If the server cannot be reached, the element opens the manual fields.
The function: find an address by postcode. Related: suggestions as you type.