I’m using the TomTom API to find the coordinates of some places and store them into a database. What I’m trying to do now is doing a range research on only those locations. Let’s say I input 10km of range and a place, I’d expect to see the list of places I’ve saved in my db that are inside that range. How can I do that? I’m using Laravel and Vue
Asked
Active
Viewed 2,162 times
3
-
Hey did my answer work for you? If so do not forget to mark it as an answer. – gguney Mar 19 '22 at 09:49
1 Answers
2
You can create a migration for your places and add these 2 columns for your lat and long:
$table->decimal('latitude', 11, 8)->nullable();
$table->decimal('longitude', 11, 8)->nullable();
After that you can store your locations inside your db.
Then you can use whereBetween condition in your query:
$locations = Location::whereBetween('latitude', [1, 100])->whereBetween('longitude', [200, 300])->get();
WhereBetween condition accepts 2 arguments, column name and min-max values respectively.

gguney
- 2,512
- 1
- 12
- 26