In my recent work, I have completed one project in Laravel application and it was very similar to the food ordering application like Swiggy/Zomato. For the database, I had used PostgreSQL object-relational and installed PostGIS extension.
PostGIS is open source software program that adds support for geographic objects to the PostgreSQL object-relational database.
I heard about the PostgreSQL database but I never used PostGIS extension so it was a new experience for me. When I was developing API for the mobile application, I had to find nearby restaurants, hotels & cinemas based upon user current location(Latitude and Longitude). So I was searching on google for how to store records with latitude & longitude and how to make queries which return records from the database and after doing some research on google, I found that PostGIS extension which helps me in this scenario.
Before we jump to the PostGIS installation part, I am assuming that you have already installed the latest version of PostgreSQL in your system.
Before you can install PostGIS extension, update your list of available packages so the packages from the new repository are added to the list.
sudo apt-get update
Once your sources update, install the PostGIS extension.
sudo apt-get install postgis
Enter Y when prompted to install PostGIS along with its necessary dependencies. Now we can connect to PostgreSQL and integrate PostGIS.
Using the sudo command and switch to the Postgres user:
sudo -i -u postgres
Connect to the
psql -d PostGISDemo
Enable the PostGIS extension on the database:
CREATE EXTENSION postgis;
Ok. Now let’s verify that everything worked correctly. Execute the following command in your terminal screen:
You’ll get this output:
postgis_version --------------------------------------- 2.4 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 (1 row)
We’re all set. Type the below command
to exit the SQL session and return to your terminal prompt.
Keep visiting for new stuff and give your feedback.
Happy Coding 😉