1

I am writing a server side java application related to Geo-fencing.

  • I have a store with their latitude,longitude and radius
  • I also have Person's current position(in terms of latitude & longitude).

If he arrives within the geo fence i.e., within the store's radius i have to give an alert. I googled for the solution & there are some methods to identify person is inside the fence(circle) or outside the fence.

  1. Calculate distance between store latitude,longitude and person's current latitude & longitude and if Distance < radius then person is inside the fence else outside the fence.
  2. Using Polygon Geofencing

Can anyone suggest me which method is best from the above.

Thanks in advance

Lakshmi
  • 53
  • 2
  • 10

4 Answers4

1

It depends on your needs. If you want to know whether a Person is inside 1km radius of store, then you need a circle search. Here, location of the store is the pivot. You might change the radius based on your need.

Polygon search is used when you need to search people in a particular area regardless of how much distance it is away from anywhere. People in Paris, New York or Istanbul area, not people inside 1km radius of a store.

Mustafa Genç
  • 2,569
  • 19
  • 34
1

In your case, where only radius (i.e. distance to the shop) is needed, I would definitely choose the radius search (your first proposition).

The Polygon Geofencing, I think, is using the Ray-Casting Algrithm which iterates over each segment of the polygon. This will take more time and could lead to some approximation in the case of a circle (depending on how the algorithm is applied).

Legisey
  • 503
  • 1
  • 4
  • 18
0

I would have thought that the best method to use here would be a radius distance calculation, presuming you need to know the distance 'as the crow flies' so to speak. So geographical distance rather than travelling distance. This will be the most performant and simplest to implement. Examples available here and here.

If the latter is the case (which I hope for your sake it isn't), then I would imagine you would need to use polygon geofencing or perhaps Google's distance Matrix API.

Community
  • 1
  • 1
ChrisSwires
  • 2,713
  • 1
  • 15
  • 28
0

Thanks for all your answers. In my project i have integrated both methods(Polygon & Distance). If a user enters into the polygon he ll get a notification and same like radius. I have stored the polygon co-ordinates and radius into my database.

Lakshmi
  • 53
  • 2
  • 10