0
votes

I have a database table with POI's that i want to connect with a record in my Geo table (containing cities, countries).

  • Within the POI table i have a Lat & Lon field.
  • Within the Geo table i have 4 coordinates, for West/East and North/South

enter image description here

I'm using Laravel 5 / Eloquent and Mysql. The coordinates are stored as a decimal (11,8). I can add multiple columns if needed.

How can i check if a POI is located within those 4 coordinates?

1
What's exactly POI ?Shady Atef
POI = Points Of InterestJackowski
Don't reinvent the wheel, use mysql's built-in spatial data types and functions.Shadow

1 Answers

0
votes

Mysql supports spatial data types and functions that were designed to make such calculations easy.

Define your POIs as POINT and your rectangle as GEOMETRY. Use the ST_Contains() function to test whether the point is within the rectangle:

select * from yourtable
where st_contains(rectangle_field, point_field)

As far as I know, Laravel does not directly support these daya types and functions, so you have to resort to raw sql.