proximity search google map

我只是一个虾纸丫 提交于 2019-12-03 19:58:37
AlbertVo

Google has a complete tutorial on creating a store locator. The vital piece of information that you are missing is how to query your database to pull back the locations within your radius.

http://code.google.com/apis/maps/articles/phpsqlsearch.html

take a look at the link above for details but the query will look somthing like this (mySQL):

SELECT
  address,
  name,
  lat,
  lng,
  (
    3959 * acos(
      cos( radians('%s') ) * cos( radians( lat ) )
      *
      cos( radians( lng ) - radians('%s') )
      +
      sin( radians('%s') )
      *
      sin( radians( lat ) )
    )
  ) AS distance 
FROM markers 
HAVING distance < '%s' 
ORDER BY distance 
LIMIT 0 , 20

It uses trigonometry!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!