Showing users things near them is a really common user need for all sorts of apps and websites.
It could be used to power anything from "branch finder" features on retail sites to nearby drivers on a ride-hailing app.
For my day job, I need to build this kind of functionality roughly once every few months, so I was keen to find a way to package it up into something reusable.
I've implemented it in Node.js and Rails before, but I was curious about a WordPress implementation - which is what this is.
After making over half a dozen apps like this, you start to wonder if there's a better way!
How it works
It's a three step process:
You provide a geocoded dataset to search. They could be shops, offices, childminders, zoosβanything, really. You make sure that they have latitude and longitude metadata.
The user provides their location with a text input, which we also geocode. We use Nominatim's excellent free API to do this.
Finally, we use the haversine formula in SQL to calculate the distance to each point in the dataset. It takes into account the curvature of the earth, so we get super-accurate results even on international scales!
The plugin
Take a look and tell me what you think!
It's my first WP plugin that I've actually gone to the extra effort of publishing, so I'm keen to keep adding features.
Top comments (0)