Forum

Thread tagged as: Question

Filter by Latitude and Longitude

Hello,

Following on from the thread: https://forum.grabaperch.com/forum/09-28-2015-distributor-locator-at-scale

I've gained ground in that I can now filter by country, calculate distances on each result and get co-ordinates for a box X miles around a given place but the final piece of the puzzle that eludes me is filtering by latitude and longitude.

I have used a map type to add locations to a collection but I'm not sure of the syntax to use for filter to get to the latitude and longitude inside the map array. I can see that the data is there if I skip-template and within the template I can create a slug for that data using for="map_lat map_lng" but that obviously urlifies the co-ordinate.

Any ideas for this final hurdle? I'd be grateful for any pointers or suggestions!

Mark Greenwood

Mark Greenwood 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to filter on map_lat and map_lng directly, I believe.

Hi Drew,

Thanks for the speedy reply. I couldn't get it to work directly for some reason but I have managed a solution! I had to create hidden fields in my template like so...

<perch:content id="map_lat" type="hidden" suppress="true" />
<perch:content id="map_lng" type="hidden" suppress="true" />

If I take them out, the filter stops working. It's like they have to appear in <perch:showall /> for it to work. But it does now!

I need time to test everything with a bigger sample of data but it seems to be working perfectly and I seem to have achieved the goal of building a location finder that works without any kind of JS.

Thank you for your help in this and the last post.