Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Codeigniter 4 Google Autocomplete Address Search Box Example

Codeigniter 4 Google Autocomplete Address Search Box Example

Posted on September 5, 2021December 13, 2022 By XpertPhp

In this article, we will explain to you how to create a google autocomplete address search box example in CodeIgniter 4(Codeigniter 4 Google Autocomplete Address Search Box Example). we can easily create the google autocomplete search box using google API in CodeIgniter 4(Codeigniter 4 search box).

In this example, we use the “Maps JavaScript API” and “Places API” services to add google autocomplete address/place the search box in Codeigniter 4. so you can see our following example.

Overview
Step 1: Download Codeigniter
Step 2: Basic Configurations
Step 3: Create Google Maps API
Step 4: Create Controller
Step 5: Create Views Files
Step 6: Run The Application

Step 1: Download Codeigniter
If you want to download or install the latest version of CodeIgniter 4 then you can go to Codeigniter’s official site and download the latest version of Codeigniter 4. after the downloaded you can configure in “xampp/htdocs/” directory.

Step 2: Basic Configurations
If you want to Basic Configurations in your project then you can below Url.
Codeigniter 4 Removing Index.Php From Url

Step 3: Create Google Maps API
In this step, we need the Google Maps API key. So first we go to the Google Cloud Platform Console, create the project and get the Google Maps API key.

Step 4: Create Controller
In this step we will create the controller “Autocomplete.php”. after creating the controller we will create the index() method and it will call the view file. for this, you can follow the example.
app/Controllers/Autocomplete.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
 
namespace App\Controllers;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\RequestInterface;
class Autocomplete extends Controller
{
public function index()
{
return view('google_search');
}
}
 
?>

Step 5: Create Views Files
Finally, we will create the list.php in the app/views directory.
app/views/google_search.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="description" content="The tiny framework with powerful features">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Codeigniter 4 Google Autocomplete Address Search Box Example - XpertPhp</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
      .container {
        max-width: 500px;
      }
    </style>
</head>
<body>
    <div class="container mt-4">
        <div class="form-group mb-3">
           <h3 class="mb-3"> Find Address or Location</h3>
           <input type="text" name="autocomplete" id="autocomplete" class="form-control" placeholder="Choose Location">
        </div>
        <div class="form-group mb-3" id="latitudeArea">
           <label>Latitude</label>
           <input type="text" class="form-control" name="latitude" id="latitude">
        </div>
        <div class="form-group mb-3" id="longtitudeArea">
           <label>Longitude</label>
           <input type="text" class="form-control" name="longitude" id="longitude">
        </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://maps.google.com/maps/api/js?key=your-api-key&libraries=places&callback=initAutocomplete"></script>
    <script>
        $(document).ready(function() {
            $("#latitudeArea").addClass("d-none");
            $("#longtitudeArea").addClass("d-none");
        });
        
        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();
                
                $('#latitude').val(place.geometry['location'].lat());
                $('#longitude').val(place.geometry['location'].lng());
                
                $("#latitudeArea").removeClass("d-none");
                $("#longtitudeArea").removeClass("d-none");
            });
        }
    </script>
</body>
</html>

Step 6: Run The Application
We can start the server and run the Codeigniter 4 application using the below command.

1
php spark serve

Now we will run our example using the below Url in the browser.

1
http://localhost:8080/autocomplete

Codeigniter Tags:Codeigniter 4 Tutorial

Post navigation

Previous Post: Codeigniter 4 Fullcalendar Example Tutorial
Next Post: Codeigniter 4 Google Column Charts Example

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JavaScript Interview Questions and Answers

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com