3

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

banjug
  • 45
  • 1
  • 5

1 Answers1

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