简体   繁体   中英

Get users within radius from coordinates in Laravel

I have a mobile app that uses Laravel as a 'backend API' to get and manipulate data. Now I send the users coordinates to the server which updates the database that the user is at a specific location, but they have specified their radius as well that they would like to search within.

How can I make a call to the database to fetch al users with coordinates within the given radius using Laravel? I have seen a few posts on the SQL query, but I am confused on how to use that inside laravel, and would feel more comfortable if there was a 'more formal' way of doing this that a DB::raw() query.

Here is a package that is 2 years old but should be able to still be applied: https://github.com/douggrubba/laravel-haversine-model

Hopefully it will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM