Geolocation: Using an events calendar program to highlight events close to the user
As part of the development of the Farm Table site, we were looking to add a geo-location feature to show a list of events within a certain distance of the currently logged in user’s address, information which is held in their private user profile.
My hopes were raised by the changelog of the Events Calendar Pro plugin, that mentioned that version 4.4.16 added the ability to include geo-location parameters in searches.
The geo-location features are usually used off the shelf in ECPro, via the Location parameters of the filter bar. What I needed to do was retrieve latitude and longitude values from the currently logged in user’s profile (ie user_meta values) and then use these values to power a search to show ‘events within x kilometres of the user’.
To store the values, we use Gravity Form’s User Registration add on (for user profile editing) and GeoMyWP and their Gravity Geolocation extension to do live lookups from Google’s geocoding service as the user is typing their address, to in turn feed a geocoder on the page, that then allows you to store any number custom meta values. It works pretty well:
When it comes to using this stored information to drive a list of ‘events near you’, the documentation was pretty scarce. I ended up reading source code to work out how it was done.