Skip to main content

This app makes it easy to display a map for given address in django templates. No API keys, manual geocoding, html/js copy-pasting or django model changes is needed.

The license is MIT.

Installation

pip install geopy
pip install django-easy-maps

Then add ‘easy_maps’ to INSTALLED_APPS and run ./manage.py syncdb (or ./manage.py migrate easy_maps if South is in use)

Usage

This app provides an easy_map template tag:

{% easy_map <address> [<width> <height>] [<zoom>] [using <template_name>] %}

Examples:

{% 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 %}

Customization

If the default map template is not sufficient then custom map template can be used. Examples:

{% easy_map address using 'map.html' %}
{% easy_map address 200 300 5 using 'map.html' %}

The template will have ‘map’ (it is the easy_maps.models.Address instance), ‘width’, ‘height’ and ‘zoom’ variables. The outer template context is passed to rendered template as well.

The default template can be found here: https://bitbucket.org/kmike/django-easy-maps/src/tip/easy_maps/templates/easy_maps/map.html

You can start your own template from scratch or just override some blocks in the default template.

Please refer to http://code.google.com/apis/maps/documentation/javascript/ for detailed Google Maps JavaScript API help.

Address model

easy_maps.models.Address model has the following fields:

  • address - the requested address

  • computed_address - address returned by geocoder

  • longtitude

  • latitude

  • geocode_error - True if geocoder wasn’t able to handle the address

Admin address preview

django-easy-maps provides basic widget that displays a map under the address field. It can be used in admin for map previews. Example usage:

from django import forms
from django.contrib import admin
from easy_maps.widgets import AddressWithMapWidget
from firms.models import Firm

class FirmAdmin(admin.ModelAdmin):
    class form(forms.ModelForm):
        class Meta:
            widgets = {
                'address': AddressWithMapWidget({'class': 'vTextField'})
            }

admin.site.register(Firm, FirmAdmin)

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!

Source code: https://bitbucket.org/kmike/django-easy-maps/

Bug tracker: https://bitbucket.org/kmike/django-easy-maps/issues/new

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-easy-maps-0.6.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file django-easy-maps-0.6.tar.gz.

File metadata

File hashes

Hashes for django-easy-maps-0.6.tar.gz
Algorithm Hash digest
SHA256 969502b572fc423ac03d46a9fc3cb13621f110df5dd6df0a48be19957183b7d2
MD5 9462efb1a840887b5380f077ee9f24b8
BLAKE2b-256 06f2f7b62558287aafdccf4efaa0496a1d0bb8cb1fdc404b900ccb58f5f8ac67

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.5

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

1 file

0.9

1 file

0.8.4

1 file

0.8.3

1 file

0.8.2

1 file

0.8.1

1 file

0.8

1 file

0.7.4

1 file

0.7.3

1 file

0.7.2

1 file

0.7.1

1 file

0.7

1 file

This release

0.6 This release

1 file

0.5.4

1 file

0.5.3

1 file

0.5.2

1 file

0.5.1

1 file

0.5

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page