Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to implement a rectangular geo fence.

I am getting the latitude and longitude co-ordinates from GPS module which gives the current position of the vehicle.
When the vehicle is parked, a virtual fence is activated. The program should check if the vehicle is within the boundary through regular position updates and alert the user in case of fence breach.

Any C code for the above implementation would be very helpful.
Posted
Updated 28-Feb-12 19:25pm
v2
Comments
André Kraak 29-Feb-12 1:25am    
Edited question:
Formatted text/code
Removed unnecessary tags
Fredrik Bornander 29-Feb-12 4:17am    
Is there a reason the fence has to be rectangular? A circular fence would be simpler (not saying that a rectangular would be that difficult) as the fence is then just a distance.
kavyabc123 1-Mar-12 3:22am    
There is no particular reason that the fence has to be rectangular, a circular fence would also suffice. Just trying to figure out the most effective implementation for my project..

1 solution

A rectangular or circular fence would be of similar ease to program.

A fence of an irregular shape would be tougher.

How about....

C++
bool IsInFence(double CurrentX, double CurrentY, double ParkedX, double ParkedY, double FenceDistance)
{
   double dX = CurrentX - ParkedX;
   double dY = CurrentY - ParkedY;
   double Distance = sqrt((dX * dX) + (dY * dY));
   if (Distance > FenceDistance)
      return true;

   return false;
}


I'll leave it up to you to finish the rest of your homework.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900