Dynamic tag for post distance in the Layout Builder

<?php
/** Creates a dynamic tag for use in the Listing Builder
 ** https://facetwp.com/help-center/developers/hooks/output-hooks/facetwp_builder_dynamic_tag_value/
 ** see https://facetwp.com/help-center/facets/facet-types/proximity/#display-the-post-distance
 ** for how to customize this output
 ** To use this dynamic tag in the Listing Builder, create a HTML element and add the tag to the "Content" field. E.g. <div class="distance"> {{ distance }} </div>
 ** Note that the distance will only be output when the Proximity facet is actually in use.
 **/
add_filter( 'facetwp_builder_dynamic_tag_value', function( $tag_value, $tag_name, $params ) {
    if ( 'distance' == $tag_name ) {
        $distance = facetwp_get_distance();
        // Round distance to 2 decimals and append ' mi'
        if ( false !== $distance ) {
            $tag_value = round( $distance, 2 ) . ' mi';
        } 
    }
    return $tag_value;
}, 10, 3 );