Posted By

martyncoup on 04/20/09


Tagged

mysql longitude latitude place nearest


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

kubaitis
virendrakryadav


Nearest Place


 / Published in: MySQL
 

  1. SELECT *,
  2. (3963.1676 * ACOS(COS(RADIANS(@latitude)) * COS(RADIANS(latitude)) *
  3. COS(RADIANS(longitude) - RADIANS(@longitude)) +
  4. SIN(RADIANS(@latitude)) * SIN(RADIANS(latitude)))) as distance
  5. FROM geoname
  6. WHERE latitude BETWEEN (@latitude - 1) AND (@latitude + 1)
  7. AND longitude BETWEEN (@longitude - 1) AND (@longitude + 1)
  8. ORDER BY distance asc

Report this snippet  

You need to login to post a comment.