Name of function/system to locate businesses within a certain distance?

On several sites, you can retrieve businesses within a certain radius of your own address. I’m trying to find a tutorial on how to create such a function/system, but no luck so far. Does it have a specific name? Or do you know of a good tutorial?

My knowledge base is HTML, CSS, JS, PHP and MySQL, but I’d like a tutorial that explains it from scratch.

1 Like

in general, it’s called geolocation, and it’s based on latitude and longitude

MySQL version 8 stores spatial data using different types of geometry data types such as POINT, LINESTRING, and POLYGON

i haven’t used any of this stuff, but here’s an article that will get you started –

4 Likes

Thanks, I’ll get into that. But let’s first see whether I got things right with respect to the construction of the system:

  1. The data of the businesses in my database have to be complemented with their geographic coordinates. For that, their address must be converted to coordinates with a Google Maps API.
  2. The website visitor looking for nearby businesses must also enter their address, which is converted as well.
  3. The visitor sets the desired radius.
  4. The server runs a MySQL query whereby the distance is calculated between the coordinates of the visitor and of all the stored businesses, and those businesses with a distance up to the set radius are presented to the visitor.

Is that how the system works? And is that the only option?

to the best of my knowledge, yes

2 Likes

In the UK you can use post codes instead of lat / long - every postcode has a “grid east” and “grid north” figure, which is some measurement from a fixed point off to the south west of the country, somewhere in the English Channel.

1 Like

In stead of coordinates? Not in MySQL, I’d think. That only accepts coordinates for the calculation of the distance.

In stead of street name and number in the web form, sure. The Google Map API can convert post codes into coordinates as well, from what I’m seeing. And that would make it more user friendly indeed.

To clarify, I wasn’t suggesting that you’d use the post code itself to calculate distance, you’d use the grid-east and grid-north references that each post code has. But for a UK web site, I’d agree that post codes are more likely to be known by the user - I know mine, but even though I used to use lat/long quite extensively in a previous career, I can’t remember it.

1 Like