I have a table called 'flags' in a MySQL database with 400,000 rows. This table is made up of geospatial points that represent different positions around the UK.
The application I'm creating uses Google Maps. On the map is a button that should toggle the flags visibility on the map. It's my job now to create an API that when passed a bounding box all flags inside the bounding box are returned (so that they can then be displayed on the map).
The passed parameters are the North East latitude/longitude and the South West latitude/longitude of the viewport's current position.
I now need to perform an SQL query that will return all geospatial points that are inside this sets of coordinates (the viewport).
Ideally the solution needs to be optimized as there are many rows to search. The application does force you to zoom into a certain level before the user can reveal the flags, however.
Flags table:
- id
- coordinates
- name
Example row:
1 | [GEOMETRY - 25B] | Tenacy AB
The coordinates field can also be converted to a literal point by using AsText(coordinates). The X and Y functions do this for you however.
The coordinates column is data type: POINT
I know that to obtain the latitude/longitude of a point you can use the X and Y functions. For example, the latitude of a point can be retrieved like this: X(coordinates)
DBMS: MySQL
DBMS version: 5.6.14