用SQL取得坐標算距離!!
SELECT *, (6371 * ACOS(
COS(RADIANS(25.077936)) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS(121.567857)) + SIN(RADIANS(25.077936)) * SIN(RADIANS(latitude))
)) AS distance
FROM docflow.dbo.location_test
GROUP BY serial, name, address, latitude, longitude, date
HAVING (6371 * ACOS(COS(RADIANS(25.077936)) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS(121.567857)) + SIN(RADIANS(25.077936)) * SIN(RADIANS(latitude)))) < 100
ORDER BY distance ASC
6371 = 公里
3959 = 英哩
google Api : https://developers.google.com/maps/articles/phpsqlsearch?hl=zh-TW
COS(RADIANS(25.077936)) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS(121.567857)) + SIN(RADIANS(25.077936)) * SIN(RADIANS(latitude))
)) AS distance
FROM docflow.dbo.location_test
GROUP BY serial, name, address, latitude, longitude, date
HAVING (6371 * ACOS(COS(RADIANS(25.077936)) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS(121.567857)) + SIN(RADIANS(25.077936)) * SIN(RADIANS(latitude)))) < 100
ORDER BY distance ASC
6371 = 公里
3959 = 英哩
google Api : https://developers.google.com/maps/articles/phpsqlsearch?hl=zh-TW
留言
張貼留言