NearHotels API Project using Django

Application Programming Interface, popularly known as APIs are used to provide extra functionality to applications using existing technologies and libraries developed others. In this project, the Here APIs for geocoding and near places were used to develop a web app for geocoding and locating nearhotels using the Django web framework. NearHotels API Project using Django was designed for learning purposes only. Although, plans to build on it and come up with a more complex application are being considered in the near future.

NearHotels API Project using Django

API web application to show a list of hotels given a location and coordinates. The coordinates are geocoded using a function referencing the Here Geocode API function, then the coordinates from the result are parsed into the near places API call to retrieve a list of locations near the coordinates specified. To trim down the search result, an address containing keywords hotel, motel, lodge was used to retrieve only relevant results and the search was limited to 5 results per call, for faster response.

Getting Started

This project was developed using Django web framework, this is not like a tutorial for how to get started with Django, simply sharing my code and steps involved in case anyone would like to learn from it or improve upon it. This quick documentation is like work through for getting the project up and running on a local server. So let’s get started with the procedures.

NearHotels API Project using Django

Setting Up Virtual Environment

  1. open cmd or terminal, run this command if you don’t have a virtual environment on your machine > pip install virtualenv

  2. create a virtual environment > virtualenv env

  3. Activate the virtual environment

  • Windows: env\Scripts\activate

  • Linux / OSX: source/bin/activate

Setting up Local Server

  1. Firstly, clone or download the GitHub repository >

  2. I am assuming you have some basic knowledge working with Django and Virtual environments as well as the command prompt interface.

  3. to clone the repository run this command > ‘git clone

  4. initialize a virtual environment on the repository you created, activate the virtual environment

  5. run the command to install all library used > pip install -r requirements.txt

  6. run the command > python migrate (to create database tables)

  7. Before running > python runserver read the API Docs

  8. Rename the .env-example file to .env and replace the API_KEY Variable with the key gotten from the here API

Here API Docs

This project uses Here API for geocoding, near places, and mapView, to access the API you will need to provide an API_KEY on the .env file.

  1. Go to > and sign up for a free developer account, create a project and navigate to your dashboard

  2. Open the service you created and click on Create API_KEY, copy the key and paste the code in the .env file, replace YOUR_API_KEY with the value from the here dashboard

Testing the Application Locally

  1. Once all configurations are set, you can run the command > python runserver

  2. By default, you access the web app through > localhost:8000

  3. From the homepage, click on the Get Started button, it will redirect you to the API form page

  4. Enter the address you wish to get nearhotels for.

  5. It posts the data and returns a list of 5 hotels close to the specified location, as well as returning the map and coordinates for the specified location

  6. To alter the result, change the near_hotels function, alter the limit parameter in the URL variable to your desired value

  7. The function for geocoding the address is found in the file, taking in the location as a parameter, it returns a JSON response with the coordinates of the location entered as well as the country name, and some other details, but we are interested in the latitude and longitude response.

NearHotels API Project using Django

Remote Test (Live-server)

The web application is hosted remotely on Heroku and can be accessed through the link below Demo:

Although the app is live on Heroku, there’s still a lot of work to be implemented, at the moment there’s no logic to store bookings of a specific hotel into the database, I would include that in the coming days. However, anyone who has implemented it can send a Pull Request to the GitHub since the code is open source.

NearHotels API Project using Django


I must admit that working on this project was a bit challenging considering it’s my first time working with API in a Django Project. I guess that’s how you become a better developer, trying out new stuff each day. The code for this project is hosted on my GitHub page, you can link to it if you need to give it a look.