Events Calendar Pro
offers the ability to perform smart location-based searches when filtering calendar events. This article aims to provide insight into how location search works in the background through the Google Maps API. If you’re interested in how to use location search, then head over to
this article
.
This requires Events Calendar Pro to be installed with a custom, unrestricted Google Maps API key, or
better, a set of restricted API keys
, which were set up based on our
Creating Google Maps API Key Restrictions article
.
How does the search happen?
When you are on a calendar page, you have a dedicated field for location search, as seen in this screenshot.
The API key used for Geocoding is restricted, and the request comes from a website, application, or IP address that is not on the allowed list.
Solution: Check the IP address restrictions for the Geocoding API key. Please also check our
related article
on how to set up restrictions for your API keys correctly.
As you can see from the above, when doing a location search, you will only get results in the calendar if the Google Maps API can return one, and only one answer, as the result.
The Google Maps API powers the location search, and it’s worth noting that we don’t have any influence over how the API itself works. We could say that the Google Maps API is a picky tool. In the end, it is “only” a machine which tries to do the best it can with the given data. It cannot guess what the user thinks. At least not yet.
The only influence we have is the search term that is sent to the API. While we cannot tell users how exactly to search to get the intended results, we do have the possibility to alter the search term based on our needs slightly.
Tweaks
Instruct users
If you have tested your location search and you found an approach that works, you can share it with your visitors as a tip. For example, you can add a short sentence below the search bar with this snippet.
add_action(
'tribe_template_after_include:events/v2/components/events-bar',
function( $file, $name, $template ) {
echo '<div style="margin-top: -32px; margin-bottom: 32px; text-align:center; width: 100%; font-style: italic;">';
echo 'When searching for a location, add the state after the city name. E.g. Springfield, MI.';
echo '</div>';
This is how that would look like on the front end:
add_filter( 'tec_google_map_args', 'tec_limit_search_to_texas' );
function tec_limit_search_to_texas( $args ) {
$args['address'] = $args['address'] . ", TX";
return $args;