Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Last active March 28, 2018 03:11
Show Gist options
  • Save zackkatz/1fccef0835aacd6693903c96ba146973 to your computer and use it in GitHub Desktop.
Save zackkatz/1fccef0835aacd6693903c96ba146973 to your computer and use it in GitHub Desktop.
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