what3words is brilliant at pinpointing exact locations. On occasions though, we still need the street address at that location – for deliveries, for example. What if I could type “slices.second.indeed” into a website, and have my street address magically appear? No chance of a mistyped street address, and the delivery driver gets an exact delivery point from the w3w – right up to the front door.
In the UK, websites often use postcodes to quickly capture street addresses. A single postcode (EG: HD5 9HL) typically represents a dozen or so street addresses (there are 1.7million postcodes in the UK, and around 29 million delivery points). From a single postcode, a drop-down list of addresses can be displayed.
This is extremely convenient, but it does have some flaws. It’s potentially expensive data, and postcode data isn’t always updated quickly when new postcodes are created. More importantly, it’s limited to the UK and although some other countries do have postcodes/zip code, they’re in varying formats (from different providers). Worse still, they’re often too large an area to show a list of addresses. (1380, for example, is the postcode for Lasne in Belgium – it represents thousands of street addresses).
Thankfully with w3w, we can build a universal system with memorable locations that works anywhere in the world and is more precise to boot (just 3m x 3m), taking the delivery right to the front door (especially useful in rural areas, or countries with ill-defined addresses).
To do this, we’ll need to do some reverse geocoding.
Reverse-geocoding (wiki) is the process of turning a location into a street address. Given a latitude/longitude of, say, 51.545427, -0.19692, we want to find the street address at this location. That requires street data, and an API. Currently, a good free API you can use is Google’s reverse-geocoder API.
Using the Google API
So to recap, we’d like to be able to convert, say, raises.delay.bath into a small range of possible addresses. Say, 17-19 Linstead Street, London NW6 2HB, UK.
In a neat blog post at Crosstek, Steve Caldwell has put together a technology demo for doing almost exactly this. Essentially, he first uses the what3words API to convert a w3w into latitude/longitude, then the Google API to get an address, all built on the meteor framework (worth checking out in itself, but way beyond the scope of this article). Check out a demo here. For technical details, check out his blog post.
Steve’s example uses the Google API for reverse-geocoding. Whilst an excellent API, it will have restrictions on usage. If we want a freer, more open solution we can tap into the excellent OpenStreetMap project’s data. David Earl, a contributor to OSM, has put together a proof-of-concept here. It uses OSM’s open-source geocoder, Nominatim. Naturally, the quality of the lookups is reliant on the quality of the underlying OSM data. Thankfully, it’s now excellent – check out the detail in this section of London. Obviously, quality will vary from country to country, but OSM does seem to be coming on in leaps and bounds.
David has kindly donated his code, about 150 lines of PHP, for all to see here. Run in on your own PHP server to check it out and use as a starting point. Please consider it to be GPL v2 license.
Geocoding and Routing
Capturing street address data using this method is ideal for things like routing and delivery. This eliminates typos in the street address, any chance of uncertainty from an ambiguous or incomplete street address. Using the precise w3w, we can also extrapolate an exact road segment ID, and a % along the road. On top of that, the w3w can give us a delivery location right to the front door, instead of the vague street-long locations common in SatNavs. Despite this precision, to ensure full integration into existing systems, we do still often need the street address to confirm the premise number for delivery (hence this post).
What about mistyping the w3w? Well, generally a mistyped w3w will lead to an invalid w3w (these can be checked with the API that a w3w is valid). In the event that a w3w is mistyped and valid, by chance it’ll often be thousands of kilometres away, and thankfully can be easily spotted (Try love.daily.tests and loved.daily.tests). This can be extremely useful for disambiguation of a w3w in voice recognition, but that’s for a later blog post.
Thanks for reading! If you have any thoughts or input on this, or projects of your own you’d like feature here in future, please do leave a comment below or get in contact at james at what3words.com.