Adding maps to your Django apps. The following steps will guide you through on how to add maps to your django projects. Along with, displaying 3D buildings. I have used Mapbox api for this project.
Head to the Mapbox. Click on "Get started". Sign up for a free account. Once you have signed in, Click the "JS Web" option. Then, choose "Use the Mapbox CDN" to install Mapbox GL JS. Once you have done that you will be provided with a access token, like this one "pk.eyJ1IjoIcGVuh29veCIsImEiOiJjampHNshreDkwbGZ5M3BxbXZkdDQ0dGdpIn1.-36WPGfz6NY90m3trPkNyw".
- Clone the repository.
- Create a virtual environment.
python -m venv djangomaps
- Activate the virtualenv
.\Scripts\activate
(Windows users)
or
source djangomaps/bin/activate
(mac users)
- This will install all the neccessary packages.
pip install -r requirements.txt
- After its done, cd into
src/maps
, openviews.py
and put the access token within the quotes. Go ahead and run the application.
python manage.py runserver
- Go to localhost
views.py
def default_maps(request):
# TODO: move Token to settings.py file
mapbox_access_token = 'PUT TOKEN HERE.'
return render(request, 'details.html', {'mapbox_access_token':mapbox_access_token})