Ok I have a database with about 1800 rows, each has a column lat and long, what I am trying to do, it query against Google Maps V3 .getBounds
From my Gist https://gist.github.com/jesuGMZ/0d7f38d80e2f67d0bc4b7fb620345344
Having MySQL >5.7 with a table that contains a column type POINT named location and the following Google Maps response:
"geometry": {
"bounds": {
"northeast": {
"lat": 40.5638447,
"lng": -3.5249115
},
"southwest": {
"lat": 40.3120639,
"lng": -3.8341618
}
},
//....
you can perform a SQL query to retrieve all your locations contains in that boundary like this:
SELECT * FROM my_table
WHERE Contains(
ST_MakeEnvelope(
ST_GeomFromText('POINT(40.5638447 -3.5249115)'),
ST_GeomFromText('POINT(40.3120639 -3.8341618)')
),
location
);
Consider to index location to improve the performance of your queries if apply. Also, is possible to use Within instead of Contains changing the order of the parameters.
Useful links: