Need correct MySQL query to list nearby posts
-
Hi guys,
I would like to list nearby posts based on m geo position. I have populated the lat & long fields of Pronamic Google Maps. My problem is that the MySQL query is not working, because everytime ist returns no records. In my try query the home geo position is 53,9 as you see in the distance calculation. I think the problem results out of the 2 not correct placed INNER JOINS. Can somebody help me ?
Thanks so much,
Mat
SELECT p.ID AS id, p.post_title AS title, pm1.meta_value AS lat, pm2.meta_value AS lon, ACOS(SIN(RADIANS(53))*SIN(RADIANS(pm1.meta_value))+COS(RADIANS(53))*COS(RADIANS(pm1.meta_value))*COS(RADIANS(pm2.meta_value)-RADIANS(9))) * 3959 AS distance FROM wp_posts p INNER JOIN wp_postmeta pm1 ON p.id = pm1.post_id AND pm1.meta_key = '_pronamic_google_maps_latitude' INNER JOIN wp_postmeta pm2 ON p.id = pm2.post_id AND pm1.meta_key = '_pronamic_google_maps_longitude' WHERE post_type = 'post' AND post_status = 'publish' ORDER BY distance ASC LIMIT 0 , 10
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Need correct MySQL query to list nearby posts’ is closed to new replies.