find which circle areas in db contain specific point on map

284 views Asked by At

I have stored in db a circle areas represented by center point (lat,lon) and radius of the circle. The fields: id, lat, lon, point, radius Now I have a some other point on the map.

My goal is to find in which areas this point exists. Already have a function for searching all points in specified area, but now I need a little different behave and find all areas contain specified point.

How will look a query which will work as mentioned?

1

There are 1 answers

0
Michał Czerwiński On BEST ANSWER

I have done research and found that in mysql 5.7 there is more spatial functions. One that comes with upgrade is SST_Distance_Sphere which worked for me! So decided to make upgrade on my server and use this SQL:

SELECT ST_Distance_Sphere(POINT(lng, lat), POINT(19.93875777348876  , 50.061379843744234)) as Radius 
FROM locations 
WHERE ST_Distance_Sphere(POINT(lng, lat), POINT(19.93875777348876   , 50.061379843744234)) <= radius