Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Forked from rafaehlers/maps-coordinates.php
Last active March 28, 2020 05:28
Show Gist options
  • Save zackkatz/b6bf5f3a49b2408801feca6b855d2374 to your computer and use it in GitHub Desktop.
Save zackkatz/b6bf5f3a49b2408801feca6b855d2374 to your computer and use it in GitHub Desktop.
Use the cordinates (Latitude and Longitude) instead of the address to position the markers over the Maps
<?php
/**
* Use the coordinates (Latitude, Longitude) instead of the address to position the markers over the Maps
*
* Replace 'MY_LATITUDE_FIELD_ID', 'MY_LONGITUDE_FIELD_ID' with field ids containing the latitude and longitude values
*
* @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 my_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 #123
if ( 123 !== (int) $form['id'] ) {
return $fields_array;
}
return array( 'MY_LATITUDE_FIELD_ID', 'MY_LONGITUDE_FIELD_ID' );
}
add_filter( 'gravityview/maps/markers/lat_long/fields_id', 'my_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