HI, Ive got a location query that Im running and he having is not matching, on mysql or Sqlite , Now sqlite dose not have some maths function so Ive added the required maths functions to sqlite .
this is my query
return $this->createModel()->select(
DB::raw("`name`, `latitude` , `longitude` , ( 6371 * acos( cos( radians(?) ) * cos( radians( `latitude` ) ) * cos( radians( `longitude` ) - radians(?) ) + sin( radians(?) ) * sin( radians( `latitude` ) ) )) AS `distance`"))
->groupBy('name')
->havingRaw("distance < ?")
->orderBy("distance")
->setBindings([$latitude, $longitude, $latitude, $radius])
->get();
and this is in my app service provider adding the required maths functions to sqlite.
$pdo = DB::connection('sqlite')->getPdo();
$pdo->sqliteCreateFunction('cos', 'cos', 1);
$pdo->sqliteCreateFunction('acos', 'acos', 1);
$pdo->sqliteCreateFunction('sin', 'sin', 1);
$pdo->sqliteCreateFunction('radians', 'deg2rad', 1);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community