Link to home
Start Free TrialLog in
Avatar of r270ba
r270ba

asked on

Geofencing

Ok I need to figure out how to write an effective and efficient geofence.  Here is my situation....I am writing a vehicle tracking application for my final project in undergrad.  This application is going to be used to track our area transit system for the school.  Obviously we have bus stops...so...I have gotten a lat/long for the stops (an approximation atleast).  Now I can add these to the database where I have all the stops information.  We also have a database that is keeping the NMEA strings for the buses locations.  

Now what I want to be able to do is...when I query to see where bus "123" currently is I would like to then have an efficient means to compare the busses current location to the coordinates I have for the stops to tell where the bus is.  I am not asking for anyone to help me with the database part (I can take care of all the myself)...what I am asking for is an idea/algorithym/psuedo code (any of the 3 would be good) to do the comparison for the buses location against the stops on the route.

I appreciate your help.

r2
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

I think the simples method for your specific application is a pitagorical calculus. Just this

distance (in feets) = sqrt ( pow(lat_bus-lat_stop, 2) + (lon_bus-lon_stop) ) * 364500

so, you define your threshold in feets and compare if it has been raised. Of couse, to apply formula you will need to convert all latitude/longitude to unique values (with decimals, without minutes and seconds)
Avatar of r270ba
r270ba

ASKER

Ok I have already written a class to parse my degrees and convert them to decimals from the NMEA string...

I am not sure what you mean with the above equation..could you explain it a little more???

I was thinking more along the lines of a select statement for the database which would do the logic for picking the correct stop....

Ex:  I take the current bus lat and long and then compare it to a stops lat/long, but with the stop lat/long I create a geofence around it...

So it would be something like

Select * from tableName WHERE 'the buses lat/long is within the geofence'

and I guess I could create a geofence by taking the stops latitude and adding a max/min lat and the stops longitude and adding a max/min long...then taking the current position of the bus and checking to see if it was...

max long > bus long < min long AND max lat > bus lat < min lat

Does this make since?  If so, then how do I determine how big my fence is?  Say my decimals are 34.655332, -82.839392...then how can I create a 20 foot box around those coordinates?

If this does not make since then what other ideas do you have?

Thanks

r2
ASKER CERTIFIED SOLUTION
Avatar of imarshad
imarshad
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r270ba

ASKER

Perfect...thanks a lot!!!