In a PHP function we want to be able to determine the closest Locations taxonomy term based on the address of the post and the addresses stored against each Location taxonomy.
Distance filters in Views are limited to Views that show posts, unfortunately, not terms or Users. So I don't have an easy way to calculate those distances or filter by those distances using Views and the Views PHP API. You would need custom PHP to calculate distance between the post address field and the term address fields, then compare all those distances. I can show you how to access custom field values but the actual geometric calculations and comparisons fall outside the scope of support we provide here since they are not directly related to Toolset and are fairly complex. Here is an example of such a calculation using lat/long values: https://www.geodatasource.com/developers/php
You could use the types_render_field function to get the lat and long of each address field without querying the DB directly. Documentation for this API is available here: https://toolset.com/documentation/customizing-sites-using-php/functions/#address
Example showing how to get the latitude of a post address field for post ID 12345:
$latitude = types_render_field( 'post-address-slug', array( 'format' => 'FIELD_LATITUDE', 'item' => '12345' ) ));
Example showing how to get the latitude of a term address field for term ID 5678:
$latitude = types_render_termmeta( 'term-address-slug', array( 'format' => 'FIELD_LATITUDE', 'term_id' => '5678' ) ));
Toolset also caches the lat/long of each geocoded address in the wp_toolset_maps_address_cache table of the database, so you could query the DB directly to access those values using the addresses stored in wp_postmeta, wp_usermeta, or wp_termmeta. Address fields from Types use the wpcf- prefix in the database, so if the slug for a term field in wp-admin is "term-location" then the termmeta key will be "wpcf-term-location".
Another requirement is that if we are look at a Locations archive page, retrieve it's address and distance_radius and then list all posts who's address falls withing the radius (miles) of the Location taxonomy term address.
This requirement is currently possible in Views without the need for custom code. Create a View of posts with a distance filter, where the distance center is set by a shortcode attribute, then use the Types field shortcode on the archive page to include the term address field in the View's shortcode attribute. Place the View shortcode in your WordPress Archive for this taxonomy, and include the term field shortcode attribute. The View shortcode would look something like this:
[wpv-view name="Name of your post View with distance filter" mapcenter="[types termmeta='term-address-field-slug' output='raw'][/types]"]
Example distance Query Filter screenshot attached.