Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Events Calendar PRO: Change default coordinates and zoom level for Map View's start location (for when there are no event results found, to avoid African coast).
<?php
/**
* Events Calendar PRO: Change default coordinates and zoom level for Map View's
* start location (for when there are no event results found, to avoid African coast).
*
* Change the coordinates to your liking. See the link below for a helpful tool.
* Updated 2018-08-06 because PRO v4.4.30 removed one of the parameters.
*
* @link https://gist.github.com/cliffordp/52d0bfb6d1537a19d158deb351dd9fa7
* @link https://boundingbox.klokantech.com/ Find the coordinates of a box on a map. Selecting "DublinCore" output will be most helpful.
* @link https://theeventscalendar.com/support/forums/topic/africa-really/
*/
add_filter( 'tribe_events_pro_localize_script', 'custom_map_view_starting_geocoordinates', 10, 2 );
function custom_map_view_starting_geocoordinates( $data, $object ) {
if ( 'tribe-events-pro' === $object ) {
// TODO: Tweak as needed to focus in on the desired geography (these ones are zoomed into New York City)
$data['geocenter'] = array(
'min_lat' => 40.477399, // south limit
'max_lat' => 40.917577, // north limit
'min_lng' => -73.700272, // east limit
'max_lng' => -74.25909, // west limit
);
if (
function_exists( 'tribe_is_map' )
&& tribe_is_map()
) {
// TODO: change to your preferred zoom level
add_filter( 'tribe_events_single_map_zoom_level', function ( $zoom_level ) {
return 15;
} );
}
}
return $data;
}
@andrasguseo

This comment has been minimized.

Copy link

@andrasguseo andrasguseo commented Oct 12, 2018

Hi Cliff,
Might be due to some changes in EC Pro 4.4.33 the Object check in the beginning needs to be like this:
if ( 'TribeEventsPro' === $object ) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment