Skip to content

Instantly share code, notes, and snippets.

@gaelg
Created October 26, 2018 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaelg/4466550a8d66d77a66271dc854b534ec to your computer and use it in GitHub Desktop.
Save gaelg/4466550a8d66d77a66271dc854b534ec to your computer and use it in GitHub Desktop.
diff --git a/geofield.module b/geofield.module
index 45cb326..41f9ddd 100644
--- a/geofield.module
+++ b/geofield.module
@@ -135,7 +135,7 @@ function geofield_radius_options() {
* The generated SQL query snippet for haversine formula.
*/
function geofield_haversine($options = []) {
- $formula = '( :earth_radius * ACOS( COS( RADIANS(:origin_latitude) ) * COS( RADIANS(:destination_latitude) ) * COS( RADIANS(:destination_longitude) - RADIANS(:origin_longitude) ) + SIN( RADIANS(:origin_latitude) ) * SIN( RADIANS(:destination_latitude) ) ) )';
+ $formula = '( :earth_radius * ACOS( LEAST(1, COS( RADIANS(:origin_latitude) ) * COS( RADIANS(:destination_latitude) ) * COS( RADIANS(:destination_longitude) - RADIANS(:origin_longitude) ) + SIN( RADIANS(:origin_latitude) ) * SIN( RADIANS(:destination_latitude) ) ) ) )';
foreach ($options as $key => $option) {
if (is_numeric($option)) {
@gaelg
Copy link
Author

gaelg commented Oct 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment