Hi, Maps 1.6 has been released, and it includes some features that help you show distance between locations as well as sort Views by distance from an arbitrary location. Please download the latest maps version to get the newest features. One new feature includes a way to sort by distance from a location added as a URL parameter. However, in your case, it sounds like this isn't ideal, because you want to specify the distance from a location relevant to the current post. That would require a shortcode attribute, not a URL parameter. So a bit of custom code is required. Here's how you can do it:
Place the map View shortcode on the template for this post type. Add the "from_center" attribute to the map View shortcode, and set the value to be the custom address field value, like this:
[wpv-view name="Your Map View" from_center="[wpv-post-field name='wpcf-location']"]
My custom field has the slug "location" but yours may be different. Add the 'wpcf-' prefix to whatever the address field slug is in wp-admin.
Next, we added a new shortcode that allows you to display the distance from that location field in the current post. Copy + paste this shortcode into your View's loop if you would like to display the distance for each item:
[toolset-maps-distance-value location='[wpv-attribute name="from_center"]' postmeta='wpcf-location']
Again, you may need to change location here to match your field slug.
Finally, a bit of custom code is required to tell the View to respond to the from_center attribute we added to the View shortcode earlier. Add this to your child theme's functions.php file, or create a new code snippet in Toolset > Settings > Custom Code:
add_filter( 'wpv_view_settings', 'ts_sort_map_by_distance_from_shortcode', 99, 2 );
function ts_sort_map_by_distance_from_shortcode( $view_settings, $view_id ) {
global $WP_Views;
$views = array( 12345 );
if ( in_array( $view_id, $views) ) {
$shortcode_atts = isset( $WP_Views->view_shortcode_attributes[0] ) ? $WP_Views->view_shortcode_attributes[0] : null;
if ( isset($shortcode_atts['from_center']) ) {
$query_center = $shortcode_atts['from_center'];
$view_settings['distance_order'] = array(
"source" => "fixed",
"center" => $query_center
);
}
}
return $view_settings;
}
Replace 12345 with the numeric ID of this View.