Tell us what you are trying to do?
I am trying to create an option checkbox 'near me', which when selected, filters posts with address that are within, say 2km of a user's location. i.e. instead of showing the fields 'Show results within XX km of [location]' and the 'use my location button', i want users to only have to click a checkbox and the filter will do its work.
Any suggestion on how to approach this concept with toolset?
Is there any documentation that you are following?
https://toolset.com/course-lesson/filtering-and-ordering-map-markers-by-distance/
Is there a similar example that we can see?
What is the link to your site?
hidden link
Hello, there's nothing exactly like this built-in to the Views filtering system, and I don't think it will be easily accomplished exactly as described for technical reasons. The "Use my location" button handles some functionality that won't be easily replicated in a custom implementation. In order to perform a distance calculation based on the User's current location, we use the browser's location API. In order to get the User's location from this API, you must get the User's permission first. When the "Use my location" button is clicked, our software tries to get that permission from the User. The browser notification says something like "Allow this site to access my location", and you may see similar notifications on other sites around the web. Once that permission is granted, the user's location is determined and made available to the search filter system. If that permission is not granted, the distance calculation will not be possible. If you remove the "Use my location" button, none of that permission management process is triggered or handled. That process is managed in a fairly complex codebase, most of which is not exposed to any public JavaScript API. So I don't have much information available that would help you set up a workaround for the "Use my location" button with custom code and a checkbox.
As far as implementing a pre-defined search radius like 2 km, that is possible in the filter configurations. You can default to any arbitrary distance here. If you want to hide the front-end number and unit inputs and related text, you would need to add custom CSS, since the individual components of the distance number input and text strings are not broken up into separate blocks or shortcodes.
My best advice is to use the existing filter setup as it's designed and not attempt to re-engineer a custom permissions interface, since there is limited support available for this type of custom filtering and the complexity of the multiple use scenarios involved here. Use CSS to hide inputs and text that you don't want to show the end User, but keep in mind that the User must grant permission to use their location, and the Use my Location button is an integral part of that process in Views.
My issue is resolved now. Thank you!