I want to write this query into Magento 2 formate
SELECT vendor_id, vendor_name, (
6371 * ACOS( COS( RADIANS( 45.4102961 ) ) * COS( RADIANS( vendor_latitude ) ) * COS( RADIANS( vendor_longitude ) - RADIANS( - 93.2434978 ) ) + SIN( RADIANS( 45.4102961 ) ) * SIN( RADIANS( vendor_latitude ) ) )
) AS distance
FROM udropship_vendor
HAVING distance <30
ORDER BY distance
LIMIT 0 , 20
Here is my query
$collection = $this->vendor->create();
$collection->addFieldToSelect(array('vendor_id', 'vendor_name', 'vendor_latitude', 'vendor_longitude', 'zip', 'street', 'city'));
$collection>addExpressionFieldToSelect('distance', new Zend_Db_Expr('( 6371 * acos( cos( radians('.$latitudeFrom.') ) * cos( radians( {{vendor_latitude}}) ) * cos( radians( {{vendor_longitude}}) - radians('.$longitudeFrom.') ) + sin( radians('.$latitudeFrom.') ) * sin( radians( {{vendor_latitude}}) ) ) )'), array('vendor_latitude'=>'vendor_latitude', 'vendor_longitude'=>'vendor_longitude'));
$collection->getSelect()->having('distance > 10');
return $collection;