Skip to content

Instantly share code, notes, and snippets.

@prezire
Last active November 4, 2022 14:42
Show Gist options
  • Save prezire/080fdd4ade10a22ab0f3 to your computer and use it in GitHub Desktop.
Save prezire/080fdd4ade10a22ab0f3 to your computer and use it in GitHub Desktop.
For NodeJS
var HaversineHelper = {
getQueryString: function
(
latitiude,
longitude,
keywords
){
return "SELECT id, post_id, full_name, description, (6371 * acos(cos(radians($latitude)) * cos(radians(latitude)) * cos(radians(longitude) - radians(longitude)) + sin(radians(latitude)) * sin(radians(latitude)))) distance FROM wp_locations WHERE full_name LIKE '%$keywords%' OR description LIKE '%keywords%' GROUP BY full_name HAVING distance < $distance ORDER BY distance LIMIT 0, 20";
}
};
module.exports = HaversineHelper;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment