BN_IT_Support Posted April 13 Posted April 13 Hello. I started with your distance calculation in Item.php: $selectClause .= ', ( 3959 * acos( cos( radians(' . $location['lat'] . ') ) * cos( radians( ' . static::$databasePrefix . 'latitude' . ' ) ) * cos( radians( ' . static::$databasePrefix . 'longitude' . ' ) - radians( ' . $location['lon'] . ' ) ) + sin( radians( ' . $location['lat'] . ' ) ) * sin( radians( ' . static::$databasePrefix . 'latitude' . ') ) ) ) AS distance'; I converted this to a PHP calculation (and I believe that I got the conversion correct!) $distance = (3959 * acos(cos(deg2rad($lat)) * cos(deg2rad($long)) * cos(deg2rad($event_long) - deg2rad($long)) + sin(deg2rad($lat)) * sin(deg2rad($event_lat)))); The problem is that this version of the calculation gave me 'NAN' (Not a Number) for the values that I tested. After a quick Google for the algorithm I found the 'Haversine formula' and that seems to work OK. $distance = 3959 * acos(sin(deg2rad($lat))*sin(deg2rad($event_lat))+cos(deg2rad($lat))*cos(deg2rad($event_lat))*cos(deg2rad($event_long)-deg2rad($long))); I conclude that your calculation in Item.php is incorrect. John
Recommended Posts