29
Views
6
Comments
Solved
Getting radius from postcode?
Question

Hi,

I have about 200 records in a database, each with a different postcode. I'd like to be able to enter a postcode + radius and then get the filtered results (all the records that are within the desired radius of the postcode). I've looked at google maps API but it seems you have to sign up/pay and ideally I'd like to avoid that.

Has anyone done this before, or know of any simple-ish ways to do this?

Any replies would be greatly appreciated!

Rank: #116
Solution

Hello Aaron,

Hope you're doing well.

Do you have the coordinates for those post codes? Like the coordinates of the central point for each post code...

If you have that information in the database, you could try to calculate the distance between the coordinates and verify if the resulting distance is less or equal to the radius.


There are several components in the Forge for this purpose.

For Traditional Web, you have this one: https://www.outsystems.com/forge/component-overview/4921/distancebetweencoordinates

And for Reactive Web, you have this one: https://www.outsystems.com/forge/component-overview/9455/distance-between-coordinates-reactive


It is just an idea, I implemented something similar in the past to find the nearest branches of a bank for a given radius of the current user location and I managed to do it using their coordinates and the distance between them.

Hope that this helps you!


Kind regards,

Rui Barradas

Rank: #3294

Hi Rui,

Thanks so much for your reply, that sounds like it should work. I only have the postcodes but can find the co-ordinates and see if that component is suitable!

Thanks,

Aaron

Rank: #116

Hello again Aaron,

I also believe it should work :)

Are you working in Traditional Web or Reactive Web?


About the first component (for Traditional), I did test it myself and it is indeed working properly. However, it is a server side component and I wanted my calculations to be as fast as possible because I was running a mobile app. So basically I didn't want to call the server everytime I was checking a distance for every single branch (I had 300+ records in the database to compare).


That's why I came with the idea to implement those calculations client side and created the second component (for Reactive and Mobile). If you have any problems with it, just let me know :)


Both components should be working as expected, as far as I can tell :)


Let me know about your conclusions!


Kind regards,

Rui Barradas

Rank: #116

Hi Aaron,

Did you manage to work it out? :)


Kind regards,

Rui Barradas

Rank: #3294

Hi Rui,

Apologies about the delay in reply.

Your component worked perfectly, and was extremely quick!

I am using Reactive Web - it was a little bit tricky as the 200 records were foreign keys in a database of around 17000 records (dealers' locations in car sales). Also, the distances needed to be unique to the user so multiple users' from different locations could get independent accurate results.

It workds perfectly now though, found the long/lat using an API from 'https://postcodes.io/' and updating a local list client side for each of the 200 records then passing the list server side to update once per user.

Thanks so much for your help!

Kind Regards,

Aaron