title: Geolocation queries in Doctrine2
body: <p>I am using Doctrine2 and CodeIgniter2 for my test application. I have a table in my database that stores all the geographic locations have fields</p>
  
  <ol>
  <li>Name</li>
  <li>Latitude</li>
  <li>Longitude</li>
  <li>Created(Timestamp)</li>
  </ol>
  
  <p>I see that the sql statement by haversine formula to select locations will look like </p>
  
  <p><a href="https://stackoverflow.com/questions/4687312/querying-within-longitude-and-latitude-in-mysql/4690450#4690450">(as mentioned in another answer)</a></p>
  
  <pre><code>SELECT id, 
  ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance 
  FROM markers 
  HAVING distance &lt; 25 
  ORDER BY distance 
  LIMIT 0 , 20;
  </code></pre>
  
  <p>Now I am finding it difficult to do this using create query builder. I am not sure if DQL or querybuilder even supports trigonometric functions. Also there are chances that my db will be migrated to postgre or can stay with MySql (yes, this is really a pain in the back) as that decision is out of my control. </p>
  
  <p>All I was told is to use doctrine's methods to achieve this and hence the db will become scalable in the future once it migrates to any of the doctrine's supported platforms. I know this is absurd. But is it really possible to query geolocation data using the latitude and longitude values in the database?</p>
  
  <p>Regards,</p>
  
  <p>Ashok Srinivasan</p>