I am using a GPS receiver and using its latitude and longitude in my application. I have saved some latitude and longitude in my database which are the latitude and longitudes of the locations through which GPS receiver will be travelled.
If GPS receiver is switched on in the middle of the two latitude and longitudes, then how will receiver know that it is in the way of these two points.(assuming receiver will not travel in a straight line).
Suppose I have a route defined in the database as A,B,C,D.
I have crossed station A and my receiver is not switched on yet. In the middle of the journey, receiver is switched on. Now my software has to configure itself such that it knows about the next coming station (in this case station B).
Assuming that the software knows that you’re traveling by train you can lookup the closest railway from your current position, verify the vector of your movement with the vector of the railway and then know in which direction you’re moving on the railway. Finding the next station then shouldn’t be too difficult.
Ok so you have the location from the receiver and want to know which is the closest station, this is the simple question. It’s harder to know which stations you have passed since routes can be very non linear, especially on rails where trains will often cover the same railway several times.
But ignoring all the problem here is a solution.
current_location=get_loc_from_gps();
sleep 10
current_direction=azimuth(current_location,get_loc_from_gps())
for station = (a,b,c,d)
distance[station]=distance(current_location,station);
d_direction[station]=current_bearing-azimuth(current_location,station);
With this you will have a list of distances to all stations, and the delta direction to them, just choose the best value…
In your code can you tell how you are calculating the azimuth angle:
current_location=get_loc_from_gps();
current_direction=azimuth(current_location,get_loc_from_gps())
for station = (a,b,c,d)
distance[station]=distance(current_location,station);
d_direction[station]=current_bearing-azimuth(current_location,station);
I am using C#.net and want to calculate azimuth angle of my location with respect to north direction. I have searched formula for it. The formula I found is using two latitudes and longitudes. But in my case I have only one latitude and longitude (of my current location).
In this case, how can I calculate azimuth angle.
Well usually you can get the current heading from the GPS and you won’t have to calculate it yourself, You can also do as I do above. I’ve edited my code for some clarity, adding a sleep there, what I do is:
I get my ccurrent location
wait 10 seconds
get a new location
calculate azimuth between those.
If you search on google for “calculating azimuth” I’m sure you will find code for C sharp as well. Code guru has a generic example you should probably read it all.
PS. this method has some serious drawbacks, making it almost unusable DS.