title: Optimizing Sqlite query for INDEX
body: <p>I have a table of 320000 rows which contains lat/lon coordinate points. When a user selects a location my program gets the coordinates from the selected location and executes a query which brings all the points from the table that are near. This is done by calculating the distance between the selected point and each coordinate point from my table row. This is the query I use:</p>
  
  <pre><code>select street from locations 
  where (  ( (lat - (-34.594804)) *(lat - (-34.594804)) ) + ((lon - (-58.377676 ))*(lon - (-58.377676 ))) &lt;= ((0.00124)*(0.00124))) 
  group by street;
  </code></pre>
  
  <p>As you can see the WHERE clause is a simple Pythagoras formula to calculate the distance between two points.
  Now my problem is that I can not get an INDEX to be usable. I've tried with </p>
  
  <pre><code>CREATE INDEX indx ON location(lat,lon) 
  </code></pre>
  
  <p>also with</p>
  
  <pre><code>CREATE INDEX indx ON location(street,lat,lon) 
  </code></pre>
  
  <p>with no luck. I've notice that when there is math operation with lat or lon, the index is not being called . Is there any way I can optimize this query for using an INDEX so as to gain speed results?</p>
  
  <p>Thanks in advance!</p>