Page 1 of 1

Calculating distance from postcode and filtering results

Posted: Fri Jul 24, 2020 9:18 pm
by johnboyuk1
Hi all

I'm not sure this is possible with anything off the peg for CMSMS but thought I'd ask here in case anyone knows...!

I need to create a database of job adverts and let the user filter by distance from a (UK) postcode - I'm not sure how I would achieve this? The database of job entries I could build with LISE, but the postcode/distance calculator to filter the results I have no clue.

Is it achievable - anyone done it?

Thanks

Re: Calculating distance from postcode and filtering results

Posted: Sat Jul 25, 2020 3:17 pm
by DIGI3
CompanyDirectory has this functionality when paired with a postcode module - I'm not sure what's available for the UK, but it's a starting point at least.

Re: Calculating distance from postcode and filtering results

Posted: Sat Jul 25, 2020 8:12 pm
by velden
I think there are two options:

1. Let some service do the calculations (Google Maps API or Open Street Maps API) for example.
They can calculate distances based on actual routes.
I don't think their services are free and it may be rather hard to implement, especially if you want to do a real-time filtering based on the user's address

2. Translate the user's address to a coordinates (longitude/latitude) and do some basic calculations on it to find the distance as the crow flies(?). I read that it's not easy to do an exact calculation but for a rather small country the deviation maybe within acceptable limits. Or perhaps there are php libraries which do better calculations for you.

The module DIGI3 mentioned uses geonames.org as a source and I see they offer downloads with postal code and lat/long coordinates

If you store the coordinates with the job entries/companies (this can be automated too) you may be able to filter the results based on a square area. It would probably need a custom db query too.

Either way it will involve some thinking and coding (or I don't know of the module doing all this for you)

Re: Calculating distance from postcode and filtering results

Posted: Sun Jul 26, 2020 7:11 pm
by johnboyuk1
ok thanks guys... think the coding maybe beyond me! Was hoping there might be a module

Company directory I cant even get to work (have submitted bug report) so cant test that to see if I could twist it into what I need