alenakha (July 15th, 2016), jomarkosabel (July 13th, 2016), onlinemedia (July 14th, 2016), styki (September 3rd, 2016)
// Use the spherical law of cosines formula to find listings
// within a given distance between two points on the earth’s surface.
$clauses['join'] .= $wpdb->prepare( "
INNER JOIN (
SELECT post_id,
( %d * acos(
cos( radians(%d) ) *
cos( radians(lat) ) *
cos( radians(lng) - radians(%d) ) +
sin( radians(%d) ) *
sin( radians(lat) )
) )
AS distance
FROM $wpdb->app_geodata
)
AS distances
ON ( $wpdb->posts.ID = distances.post_id )",
$earth_radius,
$lat,
$lng,
$lat
);
$clauses['where'] .= $wpdb->prepare( " AND distance < %d", (int) $rad );
// Use the spherical law of cosines formula to find listings
// within a given distance between two points on the earth’s surface.
$clauses['join'] .= $wpdb->prepare( "
INNER JOIN (
SELECT post_id,
( %d * acos(
cos( radians(%f) ) *
cos( radians(lat) ) *
cos( radians(lng) - radians(%f) ) +
sin( radians(%f) ) *
sin( radians(lat) )
) )
AS distance
FROM $wpdb->app_geodata
)
AS distances
ON ( $wpdb->posts.ID = distances.post_id )",
$earth_radius,
$lat,
$lng,
$lat
);
$clauses['where'] .= $wpdb->prepare( " AND distance < %f", $rad );
alenakha (July 15th, 2016), jomarkosabel (July 13th, 2016), onlinemedia (July 14th, 2016), styki (September 3rd, 2016)
There are currently 1 users browsing this thread. (0 members and 1 guests)