GravityView Maps - Center maps on custom longitude and latitude
<?php | |
// Run at 30 priority, after `wp_print_footer_scripts` has fired (20) | |
add_action( 'wp_footer', 'print_gravityview_maps_centering_script', 30 ); | |
/** | |
* Use the setCenter function to modify centering on GravityView map objects | |
* @return void | |
*/ | |
function print_gravityview_maps_centering_script() { | |
?> | |
<script> | |
jQuery( document ).ready(function( $ ) { | |
if( window.hasOwnProperty('GV_MAPS') && window.hasOwnProperty('google') ) { | |
google.maps.event.addListenerOnce( GV_MAPS.maps[ 0 ], 'idle', function() { | |
GV_MAPS.maps[ 0 ].setCenter( { | |
lat: 41.2514, // Set your own latitude here | |
lng: -97.1558 // Set your own longitude here | |
} ); | |
}); | |
} | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment