Working with addresses

Hello all,

I am newer to Wappler and am working on solving a problem. Any help or ref material you could point me to would be highly appreciated.

I am working on an app that connect customers with nearby service providers.

So I have an order form with the Google Places Autocomplete component in it. What I am trying to do is bring up a list of all providers (stored in db) within 50 miles of the address entered into the Google Places Autocomplete component and allow the customer to select one prior to submitting the order form.

What is the best way to go about doing this?

I am using Wappler with Node JS and Bootstrap 5. Google maps, places, and geocode API keys are installed.

Details will depend upon your database, but for MySQL I do this:

In the db I have a column that is a data type of POINT. This stores a spatial gis data point of the location and is created using lat/lng.

Auto complete returns information about the chosen address including lat/lng.

When searching you’ll need a custom query to either perform your exact sql, or call a stored procedure.
In that you’ll have a where clause similar to this:

WHERE ST_Distance_Sphere(p.gis_point, POINT(@pnt_lng, @pnt_lat)) < @radius_meters

You can also return the actual distance to each point with something like this in your select:

ROUND(ST_Distance_Sphere(p.gis_point, POINT(@pnt_lng, @pnt_lat)) / @meters_per_mile, 2) as distance

Now if that type of search is too slow (large recordset), you can add an extra step, which is to first search with a “bounding box” around the point, and then perform the sphere query. You can google up the details on that, but you are basically setting a min/max lat/lng and getting the value in between.

The search can actually be done with flat lat/lng columns as well, but the spatial gis points really open up a lot of possibilities for how you search the data.

1 Like

This post may also be useful

1 Like

Thank you very much! I appreciate you taking the time to explain this to me.