DEV Community

Cover image for I've published my first WordPress plugin!

I've published my first WordPress plugin!

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.

Example screens from a location-aware app

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:

  1. 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.

  2. The user provides their location with a text input, which we also geocode. We use Nominatim's excellent free API to do this.

  3. 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)