0

I am trying to find out circular and rectangular geofence logic in C. (For circle, I will have fixed radius and centre coordinate) Please help me with some links/suggestions/replies.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
user3304513
  • 11
  • 1
  • 1

1 Answers1

4

For a circular geofence the easiest approach is to calculate the distance from the centre of the geofence to your current location. You'll know you're inside the geofence when that distance is less than the geofence radius. There are many methods that can be used to calculate the distance but How do I calculate distance between two latitude-longitude points? has some good examples.

For a rectangular geofence the question is essentially finding if the current position is within a polygon. The question Checking if a longitude/latitude coordinate resides inside a complex polygon in an embedded device? has a solution written in C# that would be trivial to convert to C. While it mentions a complex polygon the same technique will work for a rectangle.

Community
  • 1
  • 1
PeterJ
  • 3,705
  • 28
  • 51
  • 71