I'm looking for the distance around a particular point.
I have these items in my db with a lat and long.
I want to get all the results around it for a specified radius.
This is how i get it:
$lat = '51,3';
$long = '4,3';
$radius = '5';
$hamsters = Hamster::select(
DB::raw("*,
( 6371 * acos( cos( radians(?) ) *
cos( radians( lat ) )
* cos( radians( long ) - radians(?)
) + sin( radians(?) ) *
sin( radians( lat ) ) )
) AS distance"))
->having("distance", "<", "?")
->orderBy("distance")
->setBindings([$lat, $long, $lat, $radius])
->get();
Now it gives me an error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long ) - radians(?) ) + sin( radians(?) ) * ' at line 4 (SQL: select *, ( 6371 * acos( cos( radians(51,3) ) * cos( radians( lat ) ) * cos( radians( long ) - radians(4,3) ) + sin( radians(51,3) ) * sin( radians( lat ) ) ) ) AS distance from
hamsters
havingdistance
< 5 order bydistance
asc)
Anybody a way to fix this?