My Calendar Pro includes geolocation features for finding venues. Development is in progress to extend this to finding events.
There are a few prerequisites to being able to use the geolocation features, due to the data and API dependencies.
Services Used
Geolocation features use the MaxMind GeoLite IP to City database for translating a user’s IP to a general location and the Google Maps API for translating address information to geographical coordinates. This database is optional; see the shortcode set up for more information.
You can obtain the free version of the GeoLite IP to City database by setting up an account and submitting a request.The form can be difficult to find. At the time I’m writing, you can sign up for the GeoLite database services at this link.
With the Google Maps API, you cannot use their ‘referer’ IP usage restrictions, as the geocoding API does not work with those restrictions in place.
Where to put the Database
The database you download is expected to be a file with the name GeoLite2-City.mmdb. My Calendar Pro expects to find it at /wp-content/my-calendar-custom/db/GeoLite2-City.mmdb. This is the common directory for adding custom files for My Calendar. The file name and path can be changed using the mcs_geolocate_db_filepath filter.
How to enable GeoLocation features
Geolocation features are enabled using the constant MCS_GEOLOCATION_ENABLED. You can set this constant in your wp-config.php file or any other standard location for configuring WordPress constant values. Do not configure it inside the my-calendar-pro directory, as it will be erased when the plugin is updated.
The Geolocation shortcode and interface.
The shortcode for Geolocation is [geolocate]
Shortcode with default values
[geolocate latitude="" longitude="" radius="100" limit="25" unit="kilometers"]
By default with the IP to City database, the shortcode will display a map centered on the current visitor’s location, showing the first 25 venues within a radius of 100 kilometers of that location.
The IP to City database is only used to detect the current user’s location – if you do not wish to do IP location detection, you can enter latitude and longitude coordinates to set the center of the map.
Only locations that have latitude and longitude coordinates in the database will appear on the map. If you have Google Maps configured, these coordinates are added automatically if there is sufficient address information.
The unit attribute only accepts “miles” and “kilometers”.
The shortcode also generates a form to search by location. The location search uses the Google Maps geocoding API to convert address data into coordinates.
