 <p>Do fetching from the database and processing in a background thread.</p> <p>Then reduce the number of coordinates in the path using the <a href="http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm" rel="nofollow noreferrer">Douglas–Peucker algorithm</a>:</p> <p><img src="https://i.stack.imgur.com/Qy1nG.png" alt="Douglas–Peucker algorithm"></p> <p>And cache the results.</p>