Laravel Google Map Integration Example with Multiple Markers

Hello artisan,

In this tutorial, I will show you, how to generate google map using google gmap api in Laravel application. So in this laravel maps tutorial, I will generate a google map using gmap api with latitude and longitude. 

We can create google map in Laravel without gmap, showing map with gmap api with another way. If you don't know the way, then this example tutorial is for you. So let's see how to do Laravel Google Maps Example.

laravel-create-google-map-from-latitude-longitude-example

 

Step 1: Create Route

In this step, we need a route to show google map in 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: How to Show Markers in Google Map Dynamically in Laravel

 

 

Hope it can help you.

 

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