Skip Navigation

[Resolved] Distance filter not working correctly

This thread is resolved. Here is a description of the problem and solution.

Problem: I am trying to set up a distance filter in a custom search View with a map, but the distance filter isn't working like I would expect. Site Users cannot select the distance radius in the filter, nor can they select the distance units (mi/km). If I manually update the URL to include the appropriate parameters, the distance filter begins working.

Solution: When using the inputs_placeholder attribute in the wpv-control-distance shortcode, you should always include the %%DISTANCE%% keyword in its contents. Otherwise the filtering system will not work correctly. You can use CSS if necessary to hide the distance and units filter inputs:

[wpv-control-distance default_distance="20" default_unit="mi" compare_field="map-address" distance_center_url_param="toolset_maps_distance_center" distance_radius_url_param="toolset_maps_distance_radius" distance_unit_url_param="toolset_maps_distance_unit" inputs_placeholder="<span style='display:none;'>Show spaces within %%DISTANCE%% of </span>%%CENTER%%"] 

Relevant Documentation:
https://toolset.com/documentation/user-guides/display-on-google-maps/filtering-and-ordering-map-markers-by-distance/

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 14 replies, has 2 voices.

Last updated by jamesK 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1357957
EXAMPLE.png

Please can you check that in the current "Toolset Maps" plugin (Version 1.8.4) when using the filter:

Show posts within 20mi radius of address/coordinates provided using toolset_maps_distance_center URL parameter.

This is working correctly?

This previously worked in Version 1.8.2 and lower.

The newer version of the plugin doesnt seem to work correctly - I had a map display a location (Shoreditch, London, UK) within 20 miles of the searched area (London, UK) and it wont show up - even when setting the filter radius to be 500 miles!

When searching the location specifically (Shoreditch, London, UK) it would show up

Would be great if you can confirm that this is working correctly please - many thanks

#1358067
FINBSURY.png

EDIT - not "Shoreditch, London, UK" - example should be "Finsbury Park, London"

#1358111

additionally when adding the text "&toolset_maps_distance_radius=15" into the url the radius is correct & shows the missing items.....

#1358279

Hi, I will run a quick test in my local environment and report back to you in a few minutes. Can you provide some additional information? If I'm not able to easily replicate the problem locally this will be helpful:
- Take a screenshot of the Query Filter panel from the View editor screen in wp-admin. Please attach that to your next reply.
- Also in the View editor screen, find the Search and Pagination panel. Copy the code and paste it in your next reply.
- Please provide a URL where I can see the problem on your live site. I'm not clear from your information here which results I should see on the map, and which ones are missing. Please elaborate for me.

#1358287

Hi, the distance filter does seem to be working for me in a local test. I tried multiple different filter distances starting with 20 and going down to 5 miles, and the results seem accurate at first glance. I'll be glad to take a look at any additional information you can share to figure out what's going on.

#1358747
London1.png
Finsbury1.png
toolset_2.png
toolset_1.png

Christian, Thank you - I attach the screen grabs you requested.

A live version is available here:
hidden link

When searching the location/address:

1. Location/Address = London, UK
(displays 2 results)

2. Location/Address = Finsbury Park, London, UK
(displays 4 results)

As Finsbury Park is within 20 miles of "London, UK" the search for "London, UK" should return the addresses from "Finsbury Park"

By adding the text: "&toolset_maps_distance_radius=20"

So the address becomes:
hidden link

All results are included as expected (ie 20 miles of London, UK)

Any assistance would be very much appreciated & thank you for your consideration

#1359129

Thanks for the extra info. I don't understand why the URL parameters do not include toolset_maps_distance_radius when you submit a search. Can you explain briefly how the URL/history manipulation is implemented? Specifically, how the /find-space/ directory is stripped when I submit a search?

Let me explain what I mean in more detail. I start here:
https://www.yoursite.co.uk/find-space/

I type "London, UK" in the Location/Address field and use the places auto-suggest dropdown to select London, UK. Then I click "Submit" and the URL is updated. Not only are the custom search View URL parameters applied, find-space/ is stripped out. Look carefully here:
https://www.yoursite.co.uk/?toolset_maps_distance_center=Finsbury+Park%2C+London%2C+UK&wpv-wpcf-property-status=to-let&wpv_view_count=897
You can see this is now pointing at the homepage URL, not the /find-space/ URL. That type of URL manipulation during custom search submission is not normal, some script is manipulating the URL or history object to achieve this. If I add the URL parameter manually now and click return to refresh the page, no results are shown at all:
https://www.yoursite.co.uk/?toolset_maps_distance_center=Finsbury%20Park%2C%20London%2C%20UK&wpv-wpcf-property-status=to-let&wpv_view_count=897&toolset_maps_distance_radius=20
That makes sense, because again, this is the homepage URL not the /find-space/ URL. So if something is modifying the URL when the search results are updated, I need to understand more about it to confirm it's not stripping the required distance parameter.

#1359139

ok so that is due to a preloader plugin: https://wordpress.org/plugins/the-preloader/

I have disabled it for the avoidance of doubt - please refresh and try again....

#1359145

oddly the same thing happens - even with the plugin disabled

#1359147

If you disabled the preloader plugin and it's still stripping the /find-space/ directory after submitting a search, either some cache is holding on to the preloader plugin files or the preloader plugin is not responsible for modifying the URL in this manner. I'll be glad to take a closer look. Is it okay for me to create a clone of your site and run some tests locally? This way I'm not breaking anything else on the live site during testing. If you approve, I'll log in and create a clone using the Duplicator plugin. Please provide login credentials in the private reply fields here.

#1360325

hi - the url stripping has been sorted, there was a problem on the SIteground server yesterday that has been fixed & also remedied that issue - i can make a staging site for you if necessary, how do i send you the details so they arent publically available?

#1360875

I will make private reply fields available here. You can share login credentials in your next reply.

#1361673

Okay thanks. If you modify the wpv-control-distance shortcode you can show inputs where the User can select the distance radius and units. Here's the current shortcode:

[wpv-control-distance default_distance="20" default_unit="mi" compare_field="map-address" distance_center_url_param="toolset_maps_distance_center" distance_radius_url_param="toolset_maps_distance_radius" distance_unit_url_param="toolset_maps_distance_unit" inputs_placeholder="%%CENTER%%"] 

The inputs_placeholder attribute is responsible for managing the display of the input fields. You should include the %%DISTANCE%% keyword to display the radius and unit inputs, along with any other information you want to display. For example:

[wpv-control-distance default_distance="20" default_unit="mi" compare_field="map-address" distance_center_url_param="toolset_maps_distance_center" distance_radius_url_param="toolset_maps_distance_radius" distance_unit_url_param="toolset_maps_distance_unit" inputs_placeholder="Show spaces within %%DISTANCE%% of %%CENTER%%"] 

It looks like the distance keyword was removed, perhaps to style the inputs in a single row. I recommend using CSS instead if you want to hide the radius and unit inputs, otherwise the filtering feature won't work correctly. For example, this modification will hide the radius and unit inputs from display, but keep them in place to support the filter:

[wpv-control-distance default_distance="20" default_unit="mi" compare_field="map-address" distance_center_url_param="toolset_maps_distance_center" distance_radius_url_param="toolset_maps_distance_radius" distance_unit_url_param="toolset_maps_distance_unit" inputs_placeholder="<span style='display:none;'>Show spaces within %%DISTANCE%% of </span>%%CENTER%%"] 

Try that and let me know if it's still not behaving as expected.

#1361893

amazing - thank you so much, works like a charm! please let me know if you have a donate/buy you a coffee option as I really appreciate your help on this one 🙂

#1361895

My issue is resolved now. Thank you!