title: How can I calculate an average speed in geolocation on mobile devices?
body: <p>Geolocation is very approximate, especially in buildings. 
  For example, behind thick concrete walls my sensors on mobile phones show me that i'm moving up to 3 meters when the device is on the table motionless .</p>
  
  <p>Which makes accurate calculations impossible in the areas which are not in the open streets.</p>
  
  <p>What I think - I can make an array of 20 geopoints in 20 seconds and get average speed, but what data should I use?</p>
  
  <p>If I take 19 distances from this array and divide them by <code>(lastTime-firstTime)</code> - I wouldn't get the average speed because of it can "jump" 3 meters without really moving, so the result will be totally wrong in obscured areas.</p>
  
  <p>So , I can take a distance between first and last geopoints and divide it by <code>(lastTime-firstTime)</code>, but... the results will be correct only if a person move perfectly straight. If he would go 10 seconds straight and after that turned right - distance will be not the real distance he walked - the sum of two cathetuses , it would be the hypotenuse of this triangle. So, this is not the way of calculating the real speed.</p>
  
  <p>What I need (I suppose) is some complex algorythm of an approximated straightened route that would be gathered into some array of <code>correctedDistances</code>and we can find a more or less true speed using them?</p>
  
  <p>Like the picture shows - red is the data we get from the sensors, and black lines are the approximate real route of a person by which we can calculate more or less faithful speed.</p>
  
  <p><a href="https://i.stack.imgur.com/XcWyd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XcWyd.png" alt="enter image description here"></a></p>
  
  <p>But may be there is already a ready-made algorythm or formula made for such tasks? I don't mean google maps or any other, just a plain formula or algorythm (may be there is much simpler logic for that than I imagine)</p>