How to Add Google Map in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

Hi Dev,

This article will give you example of laravel google maps example. if you want to see example of laravel google maps location then you are a right place. I would like to share with you how to add google map in laravel. We will use how to use google map in laravel. Follow bellow tutorial step of laravel google map marker example.

In this example, we will create one simple route and display google map with marker. We will use the google maps js library for adding google map. you can easily add a google map in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

you can see bellow preview, how it looks:


Step 1: Install Laravel

This is optional; however, if you have not created the laravel app, then you may go ahead and execute the below command:

composer create-project laravel/laravel example-app

Step 2: Create Route

In this is step we need to create some routes for google maps example view.



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\GoogleController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!



Route::get('google-autocomplete', [GoogleController::class, 'index']);

Step 3: Create Controller

in this step, we need to create GoogleController and add following code on that file:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class GoogleController extends Controller



* Write code on Method


* @return response()


public function index()


return view('googleAutocomplete');



Step 4: Google Map API Key in Env

here, we will add new variable in .env file fo set google map api key. so let's add as bellow:



Step 5: Create Blade Files

here, we need to create blade files for google autocomplete example. so let's create one by one files:


<!DOCTYPE html>

<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">


<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>How to Add Google Map in Laravel? -</title>

<script src=""></script>

<style type="text/css">

#map {

height: 400px;





<div class="container mt-5">

<h2>How to Add Google Map in Laravel? -</h2>

<div id="map"></div>


<script type="text/javascript">

function initMap() {

const myLatLng = { lat: 22.2734719, lng: 70.7512559 };

const map = new google.maps.Map(document.getElementById("map"), {

zoom: 5,

center: myLatLng,


new google.maps.Marker({

position: myLatLng,


title: "Hello Rajkot!",



window.initMap = initMap;


<script type="text/javascript"

src="{{ env('GOOGLE_MAP_KEY') }}&callback=initMap" ></script>



Run Laravel App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:

php artisan serve

Now, Go to your web browser, type the given URL and view the app output:


I hope it can help you...