# locate GPS receiver between two latitude and longitude

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).

Can you give an example with numbers, so it’s easier to understand? I can see that you have:

1. a future goal where you want to go, represented by a lat/lon
2. the current location from a GPS receiver, represented by a lat/lon.

But I’m not sure what you want to know.

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).

how can I do this…

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.

thanks…Lambertus for the reply…but can you more elaborate your answer…I am not able to understand how to look up the closest railway station…

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.