DEV Community

IRAWAN
IRAWAN

Posted on

Save coordinates to database and then do a range search

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(); 

Top comments (0)