Codeigniter 4 Get Latitude and Longitude From Address

Codeigniter 4 Get Latitude and Longitude From Address

In this article, we will explain to you how to get latitude and longitude from an address in CodeIgniter 4(Codeigniter 4 Get Latitude and Longitude From Address). we can easily get latitude and longitude from address using google API  in CodeIgniter 4.

In this example, we use the Google Maps API to getting address from lat and long 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: 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 “Geolocation.php”. after creating the controller we will create the methods index() and get_longitude_latitude_from_adress(). when we call the index() method then it will pass the address to the get_longitude_latitude_from_adress() method and then it will return the response. for this, you can follow the example.
app/Controllers/Geolocation.php

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

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

Please follow and like us: