Is the gps location between two locations

I am working on a project that will track the car while it is moving. The vehicle location is taken from the Geoloqi API and displayed on a map that is automatically updated. The coordinates are passed to the AHAH function in Drupal, which will load additional position information through some other API: s. One of them is Geonames.org.

I don’t want to download data from remote servers too often, as this increases the load and uses our loans too quickly. But. I want it to be as much time as possible, as it is important for the project. So I thought of doing this as follows:

Geonames provides a GPS location bar for the current street so that it can be drawn on a map. The β€œline” is transmitted to the next intersection. We ate our tickets too fast, if every time the place changed, we asked the name of the street, but what about at every intersection?

Is it possible in PHP to check if a given gps coordinate corresponds to a line between two other coordinates? It would be nice if this line could be extended by several meters in all directions to clear any displacement.

Thank you so much for all the suggestions.

+4
source share
1 answer

Your original question comes down to a simple math problem: find the equation of a line, given the two points that it conveys. This part is simple: let's say you have two points with coordinates (lat1, lon1) and (lat2, lon2), then the equation of the line will be

(lon2 - lon1) * X + (lat1 - lat2) * Y + (lat1 * lon2 + lat2 * lon1) = 0 

Now that you get any other point (lat, lon), just put these coordinates as (X, Y) respectively in the equation. If you get 0, then the point is on the line. Then check that your lat is between lat1 and lat2 , and your lon is between lon1 and lon2 . If so, then the new point is on the line between two existing points.

The more complex part comes from two things:

  • GPS error. To take this into account, you can make some approximation, for example, instead of comparing with 0, give it some freedom of action, for example. compare with -err to +err , where err is the specific value that you would define.

  • The fact that most of the streets are not straight. The figure below shows the problem. If you look at the line between the two ends of the upper street, the upper part of the vertical street will be on that line - but that is not what you want.
    enter image description here .

It might be better to use remote change. Do not request a position again if the distance reported by GPS has changed to less than a certain predetermined value.

+2
source

All Articles