Polygonal Google Map in Laravel with Multiple Markers

Hello Artisan,

In this tutorial, I will show you, how to create a polygon google map in the Laravel 9 application. I will create a google map where every latitude and longitude location will be connected to each other & we will do it using polygon features.

If you don't know how to create a google map in Laravel & then how to generate a map using latitude and longitude & make a polygonal map using those data then this example is for you.

For showing the google map we need the google map API key. After getting the API key, we can integrate google Maps into Laravel easily. See the below image of what we are going to make:

laravel-polygon-google-map-direction-example-with-latitude-longitude-laravel-9

 

Step 1: Create Route

In this step, we need a route to show google Maps in the Laravel application. So update web.php like below:

routes/web.php

use App\Models\Invoice;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::get('map',function(Request $request, Invoice $invoice){
    if($request->has('start_date')) {
        $data = $invoice->where('SRCode',$request->sr_code)
                        ->whereBetween('OrderDate',[
                            $request->start_date,
                            $request->end_date
                        ])
                        ->select('Latitude as lat','Longitude as lng')
                        ->get();
        return view('map',compact('data','request'));
    }
    return view('map');
})->name('google.map');

 

Step 2: Create View

Now in this step, we need a blade file for generating our google map by using our fetching data dynamically. Update map.blade.php like below:

resources/views/map.blade.php

 

Read also: Laravel Google Map Integration Example with Multiple Markers

 

Hope it can help you.

 

author-image
Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js