Geolocation Plus for HivePress

Hey @everyone, :waving_hand:

Myself and others have wished for a few more controls and options in regards to the default Geolocation extension for a while now, and I’ve been working hard to try and bring some of the communities ideas to life. I’m excited to announce my latest custom plugin is now ready for release!

Say hello to Geolocation Plus for HivePress :world_map::tada:

It sits on top of the Geolocation extension without changing a single file of it. Pick a provider and everything follows: the maps, the suggestion list, the “locate me” button, the region pages, and the link on a listing’s address.

Four more map providers

  • OpenStreetMap needs no account at all. Maps come from OpenStreetMap, address suggestions from Photon, which indexes the same data for type-ahead search.
  • MapTiler, Geoapify and LocationIQ each have a generous free tier and need a free API key.

All four are drawn with Leaflet, which is bundled with the plugin rather than loaded from anybody else’s server, and markers are clustered automatically. Google Maps and Mapbox carry on working exactly as before if you would rather keep them.

Location attributes you create yourself

A new Location field type appears in the Field Type drop-down when you add an attribute under Listings, Vendors, Bookings, Requests or Users. It suggests real places as the visitor types, exactly like the built-in location field, and it saves the coordinates alongside the address so the value carries a real position rather than just text.

Handy for a meeting point, a collection address, a second studio, or wherever a vendor actually works as opposed to where they are registered or the area they serve.

The settings that shorten or restrict the listing’s own location deliberately leave your attributes alone, so a field you have named for an address can accept one and keep it. Those settings are about the location a listing is filed and searched by, which is a different job.

Location Formatting

Choose what visitors see: the full address, the city only, the city and the country, everything except the country, or a set number of parts. Nothing is re-saved, so you can change your mind at any time and every existing listing follows immediately. There is a separate option to shorten what gets saved as people pick a suggestion, if you would rather store the short version.

Restricted Suggestions

Decide which kinds of place people are allowed to choose: countries, regions, cities, districts, postcodes, street addresses, or any combination. It is the tidiest way to keep every saved location consistent, because people can no longer pick a street address when you wanted a city. This one works on Google Maps and Mapbox too, not just the new providers.

You can also restrict suggestions to particular countries, which now applies on OpenStreetMap as well, so a UK site stops being offered the American towns that share its place names.

An Enhanced Map Block

A Location Map block for the WordPress editor and a matching [hivepress_hpgp_map] shortcode. Show your listings, your vendors, or a single place; set the height, the zoom level and the map style; filter to one category or to featured listings only.

[hivepress_hpgp_map source="listings" category="12" number="100" height="420"]

Region pages keep working

The extension can build region pages from coordinates, but only on Google Maps and Mapbox. This plugin reimplements that for the four providers it adds, adopts the region terms you already have rather than duplicating them, and gives existing ones a code it can match, so region search keeps working on a site that already has a tree.

If a lookup ever fails, the Geolocation settings page tells you which provider failed and quotes the reason it gave, rather than leaving you guessing.

A few honest notes

  • The free services are free. Photon and the OpenStreetMap tile servers are community run and ask busy sites not to lean on them. They can also be slow, and because region pages are worked out while a listing saves, a slow answer means the listing saves with its coordinates but no region page. The settings screen says so when it happens, re-saving fixes it, and moving to one of the keyed providers avoids it. Start on OpenStreetMap, move once you have real traffic.
  • MapTiler has no reliable city level in the UK. A listing in the middle of a large city with named districts can be filed under the district: a central Edinburgh address becomes “Old Town” under “City of Edinburgh”. Smaller towns and cities are named as you would expect, and the other providers do not do this.
  • Providers name the same city differently. Switching provider on a site that already has region pages can leave you with “Edinburgh” and “City of Edinburgh”. Nothing is lost, but you may want to merge them under Listings > Regions.
  • A custom location attribute is for recording and showing a second place. It stores real coordinates, but it is not plotted on the map block and cannot be searched by distance yet. The built-in Location field is still the one radius search uses.
  • Address Format has no effect on themes that supply their own address markup, which the official ExpertHive, JobHive and MeetingHive themes do.
  • The API keys are used in the visitor’s browser, as those services intend, so restrict each key to your own domain in the provider’s dashboard. The Integrations screen reminds you, and each provider’s section there has a short note on how that provider names places, so you can read it while you choose.

Requirements

WordPress 5.8+, PHP 7.4+, HivePress and the HivePress Geolocation extension, both active. The plugin says so on the Plugins screen if either is missing.

:backhand_index_pointing_right: Download the latest release here

That link always points at the current version, and updates arrive on your normal Plugins screen in WordPress.

Everything is configured under HivePress > Settings > Geolocation, with the three API keys on the Integrations tab.

Deleting the plugin keeps your settings by default, and there is a tick box if you would rather it removed everything. Every string is translatable.

This one has had a fair amount of testing: all four providers on live API keys, all six official themes, both delete paths, and the update path end to end. But every site is different, so if something looks wrong, drop a reply with the map provider you are on and I will take a look.

Feature ideas welcome as always. :slightly_smiling_face:

Hope some of you find it useful!

Cheers,
Chris :victory_hand:

P.S. If this extension saved you time or money, consider buying me a coffee! Sharing these tools for free takes a lot of time and resources, and your support helps me keep doing it for the community.

ko-fi

4 Likes

Hi Chris,

Thanks for sharing the new HivePress enhancement! :honeybee:

1 Like

Thanks for this!

For folks in the USA when selecting the address format you’ll most likely want the “everything but the last part”. it keeps everything except United States.

I downloaded this so fast because i like not seeing united states on every map like. these folks are in the usa they know its a usa link. no need to say it lol.

THANK YOU

1 Like

You’re welcome, @Bri and I’m glad you find it useful! :slight_smile:

Cheers,
Chris :victory_hand:

v1.0.6 - Plugin Update Notes

New

  • Donate link - a quiet link on the Plugins screen, for anyone who would like to support the work.

Changed

  • Consistent plugin details - the author shown on the Plugins screen now matches the rest of my extensions.

Update via your dashboard as usual! :slight_smile:

Cheers,
Chris :v:

1 Like

Hi Chris

I installed the geolocation for hivepress plugin but had to uninstall it because i was suddenly getting 504 errors that never happened before. such a great idea but i wonder what the cause of the 504 errors. It made me hesitant to try one of the other plugins since my site gets hundreds of visitors a day.

Hi @Bri,

Edit:

Bri, you found a real one, and I am sorry it cost you an outage before I’d run into the issue. You shouldn’t have to go looking through your logs; I think I’ve found the cause and pushed a quick update out for you.

What was happening is when a listing is saved, the plugin looks up the coordinates with your map provider, so it can file that listing under a region page. It was doing that lookup during the save, while the visitor waited. On the free OpenStreetMap provider I allowed that call up to twenty seconds, because the free service behind it is genuinely slow at times: I’ve measured it taking anywhere from fifteen to just under 40 seconds to answer on a bad day.

20 seconds for one save is annoying on a quiet site. On a site with your traffic it is much more than annoying, because each of those saves is holding one of your server’s PHP workers for the whole time. Most hosting plans run only a handful of workers. Once they are all sat waiting on a slow geocoder, every other visitor queues behind them, and your server eventually gives up on them: a 504 - just like you reported. Nothing to do with the page they were on, which is exactly why it looks so random.

So your report was precise, even without the logs! Hundreds of visitors a day is the condition that makes it visible. On a small test site it would have hidden for months.

Fixed in v1.0.7

The save now just makes a note that the lookup is needed, and HivePress’s own background scheduler does it moments later. Nothing waits on the geocoder any more. Measured against a deliberately slowed geocoder, the save went from 15.1 seconds to 0.04 seconds. Region pages still get built exactly as before, just a beat later.

If you would be willing to give it another go, v1.0.7 should have remedied the issue. Entirely understandable if you would rather not, and no hard feelings either way. If you do, one suggestion: Try MapTiler, Geoapify or LocationIQ rather than OpenStreetMap. They all have a free tier that will comfortably cover your traffic, and they answer in milliseconds rather than seconds. OpenStreetMap is a free community service and is the right starting point for a small site, but yours is past that.

Many thanks for reporting this rather than just uninstalling quietly. That is the only reason it is now fixed! :slight_smile:

Cheers,
Chris :victory_hand:

v1.0.10 - Plugin Update Notes

Rolls up 1.0.8 to 1.0.10.

Fixed

  • Region Search Works For Models Switched On Later - The one-off pass that gives your existing region terms their search codes skipped any model whose regions did not exist yet, then marked itself finished anyway. Switching that model on afterwards left its terms without codes, and searching one of them quietly fell back to a distance search. The pass now handles each model separately and picks up the rest later.
  • No More False “Could Not Reach GitHub” - That warning appeared when nothing was wrong, and a failed check could hide an update that was genuinely waiting.
  • Update Checks Stay Out Of Your Way - The check ran while WordPress was building the Plugins screen and could sit there for several seconds. It now runs in the background moments later.

Update via your dashboard as usual! :slight_smile:

Cheers,
Chris :v:

1 Like

v1.1.4 - Plugin Update Notes

Rolls up 1.1.0 to 1.1.4.

New

  • Separate Address Formats For Listings And Vendors - Each with an optional character limit that trims the displayed address with an ellipsis. The main Address Format still applies wherever no override is set.

  • Remove Repeated Address Parts - A provider answering “Edinburgh, Edinburgh, Scotland” displays as “Edinburgh, Scotland” everywhere addresses appear.

  • Hide The Location Field - An option on the HivePress search blocks, for a search form placed somewhere the location is already decided.

  • Hide Places Of Interest - Keeps entries such as “Edinburgh Castle” out of location suggestions, on every provider including Google Maps and Mapbox.

  • A “Default Settings” Quick Link - The quick links on the settings tab now sit at the very top, above HivePress’s own geolocation settings rather than halfway down the page, and that first group has a link of its own. Every group on the tab can now be reached from the links.

Fixed

  • The “locate me” button now works on Mapbox. Its reverse lookup borrowed the forward search request, whose parameters Mapbox refuses, so the button silently did nothing.

  • The button no longer sits there apparently dead when the browser cannot supply a position. It gives up after ten seconds and asks the visitor to type the address instead.

  • Suggestion Types now takes effect in full on Mapbox. Only the first five kinds of place were sent, so a site allowing more had the rest quietly ignored.

Update via your dashboard as usual! :slight_smile:

Cheers,
Chris :v: