Andrey Matveev Andrey Matveev - 5 months ago 41
MySQL Question

Selecting points within a bounding square

Help to make a selection from the database (mysql) of the coordinates.There is a table with fields latitude/longitude.The sample should be in the form of a rectangle. Thank you! example

I tried it, but it is necessary in the form of a predetermined size of the rectangle


If you need select the point inside a rectangle is Assuming that your rect have thr coord ($minLat , $minLng , $maxLat, $maxLng) You can simply select the points this way

        select * from my_table 
        point_lat >= $minLat 
        AND point_lat <= $maxLat
        AND point_lng  <= $maxLng
        AND point_lng  >= $minLng;