Using Low Search Results without Form to List Entries based on location relative to user lat/long
Is it possible to use Low Search results tag without a form, but using filters to sort results based on the user's current lat/long based on geocoding the IP address?
For instance, I have a set of entries for different locations of a business. I want to list the locations from closest to farthest based on the user's lat/long which I am geocoding from their IP address. I know the location may not be exact, but for now I am just trying to get the listings to work. I have a sample template:
{exp:stash:set parse_tags="yes" }
{exp:gmaps:geocoder
ip="CURRENT_IP"
}
{result}
{stash:userLat}{latitude}{/stash:userLat}
{stash:userLong}{longitude}{/stash:userLong}
{/result}
{/exp:gmaps:geocoder}
{/exp:stash:set}
{exp:stash:set name="pageContent" parse_tags="yes"}
{exp:low_search:results
channel="locations"
limit="999"
distance:from="{exp:stash:userLat}|{exp:stash:userLong}"
distance:to="location_latitude|location_longitude"
distance:radius="10000"
distance:unit="mi"
}
{title} - {low_search_distance}
{/exp:low_search:results}
{/exp:stash:set}
{exp:stash:pageContent}
I am getting results from this, but the results are not what I would expect. It is listing the locations, and it is showing them in order by distance, but the distances are much larger than I would expect which makes me think that it is not using the correct distance:from value.
Can you help me to figure this out?
Replies
Low 12 May 2016 19:05
You don't need to use a form, no. But if you're using tags as input for another tag's parameters, you'll need to add parse="inward" to the latter. Try adding that to the Results tag.
You can also try and enable the template debugger and look up the lines that mention Low Search. That can give you more insight as to what is happening exactly.
Brian Rivet 12 May 2016 19:40
Thanks Low. That took care of it.
Thanks!
Brian