1

I have around 100 geofences (polygons) defined and stored in DB. My tracking devices updates it location once a minute. What could be the best way to check a given LatLng is in any of these geofences? I want to trigger alert when the device in any of these geofences.

What I could think is, in each minute after receiving the location from tracking device, I have to query geofence information from DB or array and compare one at a time. But this seems computationally expensive.

Any idea and help, please..

asiph
  • 57
  • 3
  • 9
  • Check this link: http://stackoverflow.com/questions/6522484/google-maps-v3-check-if-point-exists-in-polygon – chrki May 12 '13 at 17:26
  • Thanks for the link. I can check if the point is in a selected polygon. But the issue here is I have several polygons and I don't know which polygon I have to check. Therefore, all polygons to be checked, which will slow down javascript. I'm looking for an effective method to do this. – asiph May 20 '13 at 10:35

1 Answers1

1

Assuming that the stored geo-fences are relatively static (i.e. not modified/added/deleted frequently) you could trade storage space for point look-up time by choosing to represent your geo-fences with a suitable spatial data structure.

R-Trees (https://en.wikipedia.org/wiki/R-tree) for example could be used to store which geo-fences might be applicable to a given point location so that only a subset of those fences need to be checked to determine if the point lies within them.

Pragmatically, you are likely best off using already existing spatially enabled databases like PostgreSQL+PostGIS (http://postgis.net/) which allow you efficiently post queries based on spatial relations (in your application likely ST_Within or ST_Contains)

krilid
  • 186
  • 1
  • 4