Part 4: Creating a location-based app for Heroku in Termux on Android

In the last few parts of our tutorial series, we have been developing a Django web application on Android using Termux, deploying it to Heroku. However it is here that we will be limited in our development on Android as geospatial database package is not supported on Termux as of yet; this will only hinder our ability to run the app locally as we can still create the app and deploy it on Heroku.

Image for post
Image for post

Here we are going to make a simple location app that will display the user’s position on a map on our website. The project is available now on Github.

Adding Linux packages necessary for a geospatial database:

We then add the PostGIS extension to our Postgresql database (see part 3 for our postgres database tutorial):

Quit by typing:

This extension is especially to make postgresql work better with spatial data.

Edit name_of_app/ to add geodjango to installed apps:

Login to Heroku and set Heroku to use the geospatial libraries from the default python buildpack:

The necessary Gdal library is not available in Termux, so we can’t install Gdal using pip. Before starting a new app inside Django, we need to comment the geodjango line in

Then start a new application with:

Add the app and uncomment the following line in settings:

Edit the in the name_of_application folder, it should reflect what is inside the name_of_application/ file:

Specify the template directory in settings, where Django will look for html files:

Let’s start with displaying a basic OpenStreetMap on the home page of our application.
First install Leaflet for Django. Leaflet is an open-source JavaScript library for displaying interactive maps. The Django module is an integration of Leaflet into the web framework for easier use.

Add the application to settings:

Edit name_of_application/

Now we need to tell Django which url will link the view and the template. We are going to use a file inside name_of_application to store all of the urls related to the application so that the code is clearer. Edit name_of_app/ and add the following:

Now create the file in which we specify the home page URL to load the view created earlier:

Now to create the folder structure for the template. First in the app root folder (with create:

Nowadays, web browsers require a website to use SSL encryption, https in order to let the user allow sharing his location. Fortunately, any Heroku app can be accessed using the SSL certificate. Just put https in the URL to your app and you will be able to share your location with the app:

Using programming for marketing and work efficiency

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store