title: location Points: distance to a specified route
body: <p>First let me state the idea:</p>
  
  <p>I want to check the distance of a user to a specified route. The route consists of multiple Location Points (In the picture, point a, b, c, d). Two adjacent points describe a vector (the blue lines ab, bc, cd in the picture)</p>
  
  <p><img src="https://i.stack.imgur.com/G0IYg.png" alt="vector location distance"></p>
  
  <p>Now to the application (android in particular, but that is not part of this question)
  The users location is tracked while he is traveling along the route. With every new location I want to check, if the user is still on the route (or within a distance X).</p>
  
  <p>I drew 3 possible locations along the route:</p>
  
  <ul>
  <li><p>location 1 is no problem. I drop the perpendicular from point 1 to the vector ab. That gives me a location point on this vector and I can calculate the distance between the two points (with android: <code>Location.distanceTo()</code>)</p></li>
  <li><p>location 2 as I am dealing with vectors, they have no beginning and no end. The black line is the projection of vector ab. Calculating the nearest distance would give me a close distance to vector ab, but a far one from vector bc. Indeed I would need to calculate the distance to bc because that is how the route is proceeding. But how do I know in my algorithm which vector I need to choose to calculate the distance to?</p></li>
  <li><p>location 3 gives me th possibility to calculate with vector ab or bc. Both are nearly equally close. How to know which one to choose?</p></li>
  </ul>
  
  <p><strong>to round this up:</strong></p>
  
  <p>I have an array with location points:</p>
  
  <pre><code>{[lat1, lon1], [lat2, lon2],[...]}
  </code></pre>
  
  <p>My application is tracking the users location. I now want to compare the new location to this track in the array.</p>
  
  <p>Does someone know an algorithm which is covering the problem, or could someone help me with the algorithm? (Pseudocode is sufficient)</p>
  
  <p>//edit: I just read about the Quadtree algorithm. Maybe that is an option in addition to the implementation of Soonts.</p>