1

I have saved bounds in my database table coming from google maps. Now i have to show these entries based on matching the bounds.

For example, I have a table for dashboard entries that are based on locations/bounds. I am saving bounds against each dashboard entry that is returned by google maps. Now, if user wanted to see the dashboard posts that are related to his city/country then i have to do matching based on user city/country bounds with dashboard entries bounds. So for that user, all those dashboard entries will appear whose bounds overlaps with user city/country bounds.

Right now i am trying with MySql OVERLAPS. But I amm unable to get proper result :(

Dump of table with some test entries:

INSERT INTO dashboard_entries 
  (id, category_id, entry_title, entry_description, customer_id, entry_date, latitude, longitude, bounds_ne_lat, bounds_ne_lng, bounds_sw_lat, bounds_sw_lng)
VALUES (150, 10, 'Blog Post for China Trip', 'Test Description', 43, '2012-02-08 15:17:46', '48.229147', '16.346052', 39.9084350, 78.6526391, 32.5301142, 116.3918633), (151, 16, 'Trip Post for Lahore Pakistan', 'Trip Post for Lahore Pakistan', 43, '2012-02-08 15:19:14', '48.229147', '16.346052', 34.0160320, 66.6578507, 24.7482340, 75.3818660); 

Here is the query that i am using:

select * 
from dashboard_entries 
where Overlaps(GeomFromText('Polygon((34.0160320 66.6578507,34.0160320 75.3818660,24.7482340 75.3818660,24.7482340 66.6578507,34.0160320 66.6578507))'), GeomFromText('Polygon((bounds_ne_lat bounds_ne_lng,bounds_ne_lat bounds_sw_lng,bounds_sw_lat bounds_sw_lng,bounds_sw_lat bounds_ne_lng,bounds_ne_lat bounds_ne_lng))'))
4

1 回答 1

1

我已经使用 mysql 的 INTERSECT 函数来找到两个矩形的交点。我相信 Overlaps 功能还没有实现。它需要两个矩形边界参数,如下所示。第二个参数也是保存在数据库中的多边形。

SELECT * 
FROM dashboard_entries 
WHERE intersects(GeomFromText('Polygon((34.0160320 66.6578507,34.0160320 75.3818660,24.7482340 75.3818660,24.7482340 66.6578507,34.0160320 66.6578507))'), location_bounds)
于 2012-05-16T07:34:28.880 回答