This app makes it easy to display a map for a given address
Project description
django-easy-maps
This app makes it easy to display a map for any given address in django templates. No manual geocoding, html/js copy-pasting or Django model changes are needed.
Authored by Mikhail Korobov, and some great contributors.
Installation
First install the module, preferably in a virtual environment. It can be installed from PyPI:
pip install django-easy-maps
Setup
You’ll need to add easy_maps to INSTALLED_APPS in your project’s settings.py file:
INSTALLED_APPS += [
'easy_maps',
]
Then run ./manage.py migrate to create the required database tables.
Configuration
The only mandatory configuration is the EASY_MAPS_GOOGLE_KEY variable:
EASY_MAPS_GOOGLE_KEY = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ___0123456789'
If you need a place to center the map at when no address is inserted yet, add the latitude and longitude to the EASY_MAPS_CENTER variable in your settings.py like the following:
EASY_MAPS_CENTER = (-41.3, 32)
Other optional settings:
# Optional
EASY_MAPS_ZOOM = 8 # Default zoom level, see https://developers.google.com/maps/documentation/javascript/tutorial#MapOptions for more information.
EASY_MAPS_LANGUAGE = 'ru' # See https://developers.google.com/maps/faq#languagesupport for supported languages.
Please see the example application. This application is used to manually test the functionalities of this package. This also serves as a good example.
You need Django 1.8 or above to run that. It might run on older versions but that is not tested.
Usage
First of all, load the easy_map_tags in every template where you want to use it:
{% load easy_maps_tags %}
Use:
{% easy_map <address> [<width> <height>] [<zoom>] [using <template_name>] %}
For example:
{% load easy_maps_tags %}
<!-- Default map with 300x400 dimensions -->
{% easy_map "Russia, Ekaterinburg, Mira 32" 300 400 %}
<!-- Variable address, custom detail level and custom template -->
{% easy_map address 200 200 5 using "map.html" %}
The coordinates for map will be obtained using google geocoder on first access. Then they’ll be cached in DB. Django’s template caching can be used later in order to prevent DB access on each map render:
{% load easy_maps_tags cache %}
{% cache 600 my_map firm.address %}
{% easy_map firm.address 300 400 %}
{% endcache %}
Templates
If the default map template is not sufficient then a custom map template can be used. For example:
{% easy_map address using "map.html" %}
{% easy_map address 200 300 5 using "map.html" %}
The template will have map (easy_maps.Address instance auto-created for passed address on first access), width, height and zoom variables. The outer template context is passed to the rendered template as well.
You can start your own template from scratch or just override some blocks in the default template.
Please refer to https://developers.google.com/maps/documentation/javascript/ for detailed Google Maps JavaScript API help.
Widgets
django-easy-maps provides a basic widget that displays a map under the address field. It can be used in the admin for map previews. For example:
from django import forms
from django.contrib import admin
from easy_maps.widgets import AddressWithMapWidget
from .models import Firm
class FirmAdmin(admin.ModelAdmin):
class form(forms.ModelForm):
class Meta:
widgets = {
'address': AddressWithMapWidget({'class': 'vTextField'})
}
admin.site.register(Firm, FirmAdmin)
address field should be either a CharField or TextField.
Contributing
If you’ve found a bug, implemented a feature or customized the template and think it is useful then please consider contributing. Patches, pull requests or just suggestions are welcome!
License
django-easy-maps is released under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-easy-maps-1.1.3.tar.gz
.
File metadata
- Download URL: django-easy-maps-1.1.3.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8ef8545edb6fa956d5af80da6e1ca95011be035a27df019cbac9bde6d71a485 |
|
MD5 | 8a676ed32b0e1c4a9abfae3ae2d76639 |
|
BLAKE2b-256 | adfdcf55555141e72eb4edc71d572ea13fa88bb72c57d83f772b7721c9f2ebc5 |
File details
Details for the file django_easy_maps-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: django_easy_maps-1.1.3-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 975f5b5c819ed83fd95d7bb99b3fb8927e6d4841de1cc7006d405f412e6020e5 |
|
MD5 | e87d8862674ca1d5eed5c2994124d125 |
|
BLAKE2b-256 | 85211983fd9c3a13ddd9c49b187a4830dd1eb25f382a44c061bc2253721b6435 |