Anyway to extend Craft Entry query search in Craft 3 I've had to manually do an SQL call to the get correct results but I was hoping there would be a tidier way of achieving this in Craft 3?

$query = ( new Query() )
-&gt;select('craft_content.title, craft_entries.id, ( 3959 * acos( cos( radians(' . $latitude . ') ) * cos( radians( field_clubLatitude ) ) * 
            cos( radians( field_clubLongitude ) - radians(' . $longitude . ') ) + sin( radians(' . $latitude . ') ) * 
            sin( radians( field_clubLatitude ) ) ) ) AS distance')
-&gt;from( 'craft_elements' )
-&gt;where('field_clubLongitude != "" and field_clubLatitude != ""')
-&gt;join( 'LEFT JOIN', 'craft_entries', 'craft_elements.id = craft_entries.id' )
-&gt;join( 'LEFT JOIN', 'craft_content', 'craft_elements.id = craft_content.elementId' )
-&gt;andHaving('distance &lt; 100')
-&gt;orderBy('distance')
-&gt;limit(3);
The "proper" way to access the element query that gets generated is through a plugin via the ElementQuery's query and subquery properties.

It looks like you're doing a Haversine algorithm to calculate distance between a latitude and longitude.  There's are some similar plugins that already do this you can use as an example.

For example: https://github.com/ethercreative/simplemap/blob/v3/src/services/MapService.php