Andrey Matveev Andrey Matveev - 17 days ago 7
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 http://www.movable-type.co.uk/scripts/latlong-db.html, but it is necessary in the form of a predetermined size of the rectangle

Answer

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 
        where 
        point_lat >= $minLat 
        AND point_lat <= $maxLat
        AND point_lng  <= $maxLng
        AND point_lng  >= $minLng;
Comments