How to Google Autocomplete Address in Laravel 11?




How to Google Autocomplete Address in Laravel 11?

Hi, Dev

In this tutorial, we'll explore integrating Google Autocomplete for addresses into a Laravel 11 application using the Google Maps Places API.

Google Autocomplete Address is a functionality offered by Google Maps, a widely-used online mapping service. Its primary aim is to streamline and accelerate the address input process by predicting and offering address suggestions as users type into the search bar. When a user initiates typing in an address within the search bar on Google Maps or any other Google platform utilizing this feature, Google's algorithm immediately begins predicting and proposing potential addresses based on the entered text. These predictions appear in a dropdown menu below the search bar, allowing users to select from the suggestions or further refine their search by continuing to type.

Sometimes we need to use Google Maps autocomplete API for getting correct addresses with latitude and longitude with Laravel. I will help you step by step how to use the Google Maps API for autocomplete addresses in a Laravel app.

Step for Google place autocomplete API with Laravel 11?

Step 1: Create Route

Step 2: Create Controller

Step 3: Google Map API Key in Env

Step 4: Create Blade File

Run Laravel App

Step 1: Create Route

In this step, we need to create some routes for Google Autocomplete Address Example view.



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\GoogleController;

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

Step 2: Create Controller

In this step, we need to create a `GoogleController` and add the following code to that file:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\View\View;

class GoogleController extends Controller



* Write code on Method


* @return response()


public function index(): View


return view('googleAutocomplete');



Step 3: Google Map API Key in Env

Here, we will add a new variable in the .env file to set the Google Maps API key. So let's add it as below:



Step 4: Create Blade File

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


<!DOCTYPE html>



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

<title>How to Google Autocomplete Address in Laravel 11?</title>

<link href="" rel="stylesheet" crossorigin="anonymous">

<script src=""></script>



<div class="container">

<div class="card mt-5">

<h3 class="card-header p-3">How to Google Autocomplete Address in Laravel 11? -</h3>

<div class="card-body">


<div class="form-group">


<input type="text" name="autocomplete" id="autocomplete" class="form-control" placeholder="Choose Location">


<div class="form-group" id="latitudeArea">


<input type="text" id="latitude" name="latitude" class="form-control">


<div class="form-group" id="longtitudeArea">


<input type="text" name="longitude" id="longitude" class="form-control">


<button type="submit" class="btn btn-primary mt-2">Submit</button>





<script src=""></script>

<script src=""></script>

<script type="text/javascript"

src="{{ env('GOOGLE_MAP_KEY') }}&libraries=places" >


$(document).ready(function () {






google.maps.event.addDomListener(window, 'load', initialize);

function initialize() {

var input = document.getElementById('autocomplete');

var autocomplete = new google.maps.places.Autocomplete(input);

autocomplete.addListener('place_changed', function () {

var place = autocomplete.getPlace();










Run Laravel App:

Now we are ready to run our example. so run bellow command so quick run:

php artisan serve

Now you can open bellow URL on your browser:




I hope it can help you...

#Laravel 11