Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Last active May 30, 2020 05:04
Show Gist options
  • Save zackkatz/98e64c074b707eee30394e8c49528a12 to your computer and use it in GitHub Desktop.
Save zackkatz/98e64c074b707eee30394e8c49528a12 to your computer and use it in GitHub Desktop.
GravityView Maps - Using coordinates example, with values filled-in
<?php
/**
* Use the coordinates (Latitude and Longitude) instead of the address to position the markers on the maps
*
* @see https://docs.gravityview.co/article/300-how-can-i-use-the-latitude-and-longitude-form-fields-to-position-map-markers
*
* @param array $fields_array Gravity Forms fields IDs containing the latitude and longitude
* @param GravityView_View $gravityview_view Current View object
*
* @return array Array with field IDs of latitude and longitude fields (Example: [ 5, 6 ] ). Empty array if not the form we want to override.
*/
function example_gv_maps_lat_long_fields( $fields_array = array(), $gravityview_view = null ) {
$form = $gravityview_view->getForm();
// Only use these fields to provide the coordinates for Form ID #46
if ( 46 !== (int) $form['id'] ) {
return $fields_array;
}
return array( '6', '7' );
}
add_filter( 'gravityview/maps/markers/lat_long/fields_id', 'example_gv_maps_lat_long_fields', 10, 2 );
@rafaehlers
Copy link

Here's an example for several forms with different field IDs:

function example_gv_maps_lat_long_fields( $fields_array = array(), $gravityview_view = null ) {
	$form = $gravityview_view->getForm();
	$formid = (int) $form['id'];
	
	switch ($formid) {
	    case 41: // form ID = 41
	        return array( '1', '2' );
	        break;
	    case 42: // form ID = 42
	        return array( '3', '4' );
	        break;
	    case 43: // form ID = 43
	        return array( '6', '7' );
	        break;
	    default:
	       return $fields_array;
	}

}
add_filter( 'gravityview/maps/markers/lat_long/fields_id', 'example_gv_maps_lat_long_fields', 10, 2 );

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