All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Sort entries (Properties) by distance

Franz 24 Jan 2014 19:52 question, complete

Here's the current situation:

- I have property entries with longitude and latitude (trough Geotagger)
- I'd like to use Low Search to search trough these entries and sort them by distance from a certain address / postal code (at least postal code)
- The person searching should not need to enter longitude / latitude to search / sort these entries

How can I accomplish this?
Let's say they enter a postal code 12345. How does Low Search know which longitude / latitude this postal code is at?

Replies

  1. Low 25 Jan 2014 10:39

    The only thing Low Search can do for you, is using lat/long info for the distance filter. So, you could dynamically set the from and to values for the lat/long properties, but you do need to take care of that yourself. The Distance filter will only calculate the distance based on those values.

    It won't work with postal codes; you'll have to convert postal codes to lat/long values yourself before sending them off to Low Search.

    If you're using the Distance filter, results will be automatically ordered by distance (shortest first).

  2. Franz 25 Jan 2014 11:44

    I appreciate your response! Is it possible to change the format?

    Default you show on the website is this:
    <input type="hidden" name="distance:from" value="52.163298|4.505547">

    However, I have found a way to populate the field like this:
    <input type="hidden" name="location" value="52.163298,4.505547">

    - Google Maps supplies a "," rather then a "|"
    - I need to use the name "location" rather then "distance:from". Is it possible to use both?

  3. Low 25 Jan 2014 11:47

    If you're populating it via either PHP or JS, then you should be able to change the values yourself, by simply replacing the comma with a pipe, and change the name of the input field, too.

  4. Steve Rowling 30 Apr 2014 09:00

    Hi Franz

    Did you manage to solve this issue? I am facing a similar problem, but I am currently stuck on how to update a hidden form field on submit so that the value is posted with the form data.

    Would you mind sharing your solution to the problem?

    Thanks

    Steve

  5. Franz 30 Apr 2014 20:20

    Hi Steve,

    Unfortunately we decided to drop the distance search - there's no solution from our side either.

    Best,
    Franz

  6. Steve Rowling 30 Apr 2014 21:25

    After further work on this today, I am happy to say that I have solved the problems I was having and distance searching is now working well for me.

    I had initially tried using JS to catch the form onsubmit event to geocode a postcode field and inject the latitude and longitude values into a hidden field before submitting the form.

    However, for some reason, the hidden field contents were never sent with the form submission.

    So I changed to putting the JS geocode on the blur event of the postcode field. This gives enough time for the geocode to complete and the hidden field to be filled in before the form is submitted and is working well.

    I have also added a validation step to the postcode blur event script so that I can check a valid postcode is in there before I attempt the geocode.

    Hope this helps with your problem.