When you insert a Toolset map, you can filter markers or order them by distance. You can also calculate the distance between two given points.

Filtering Markers by Distance

When displaying multiple markers on a map, you can add front-end controls that allow visitors to filter the markers by distance. They enter the location and a distance radius within which to display markers. If your site is using HTTPS protocol, visitors can also use their own location as the center of the search.

For example, on a real estate site, they could use this filter to display only property listings that are in a 50-kilometer radius from New York.

The best thing about the Distance filter is that it can be combined with any other Toolset filter. For example, you can allow visitors to display only properties that can be rented (and are not for sale) and are within a 50-kilometer radius from New York.

To add a Distance filter, make sure that the Filter Editor section is enabled for your View or a WordPress Archive. If it is not, scroll to the top of the editing page, click the Screen Options tab in the top right corner and select Filter Editor in the Filter section.

Scroll to the Filter Editor section, click on the New filter button, and in the dialog that appears, click the Distance button. A dialog with all the options for your distance filter appears. It allows you to customize the default radius, change labels for displayed controls, and more.

One of the important options for a Distance filter is the Comparison field. The filter uses a custom field selected under this option to get the location of each marker. Currently, this custom field needs to be of the Address type. In other words, the posts you are displaying must feature a custom Address field. You can also choose between displaying results that are Inside of radius or Outside of radius.
In order to use the option, Distance center is set from user location your website must use HTTPS. If this option is selected, the user’s current location will be used as a center point for the filter radius.

If you have a view that uses visitor location as a center point for distance filter you need to enclose it inside Your location is needed to show this content. shortcode.

If you are using Distance filter as part of a custom search you can use it to allow users to search posts using map distance. If you are combining this filter with other filters be sure to set Should distance center input be required value to No.

Distance filter settings

Ordering Views by Distance

When a View is listing posts, users, or taxonomy terms that have an Address field type, you can order the output by distance.

Edit a View and scroll down to the Ordering section. There, select to order by a custom field of an Address type. In the third drop-down, select the As a distance from option.

Fourth drop-down allows you to select if the distance is from a fixed location or the current user’s geolocation.

Selecting the Fixed option will make a fifth option field to appear. It’s an autocomplete field so just start typing the name of the wanted location.

Ordering View by a distance from a fixed location

If you select the Visitor Location option, you have to wrap your View in a wpv-geolocation shortcode. For example, if you inserted your View in a page, it would look something like this:

[wpv-geolocation] [wpv-view name="views-1472"] [/wpv-geolocation]

When ordering a View output by a field that contains an address, you can also use a URL parameter to set the center point. In this case, you must use the toolset_maps_distance_center as the URL parameter. You can use this in combination with a custom distance filter to filter results based on distance from the value provided within the URL parameter.

Displaying a distance between two locations

If you want to calculate the distance between two given points, click the Distance value button in the Fields and Views insertion dialog. Then, enter the desired values in corresponding fields. 

You can also use the toolset-maps-distance-value shortcode to display the distance between two locations.