Skip to main content

This app makes it easy to display a map for a given address

Project description

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

Authored by Mikhail Korobov, and some great contributors.

https://img.shields.io/pypi/v/django-easy-maps.svg https://img.shields.io/pypi/dm/django-easy-maps.svg https://img.shields.io/github/license/bashu/django-easy-maps.svg https://img.shields.io/travis/bashu/django-easy-maps.svg

Installation

Either clone this repository into your project, or install with pip install django-easy-maps

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.

Upgrading from 0.9

Upgrading from 0.9 is likely to cause problems trying to apply a migration when the tables already exist. In this case a fake migration needs to be applied:

./manage.py migrate easy_maps 0001 --fake

Configuration

The only mandatory configuration is the EASY_MAPS_GOOGLE_MAPS_API_KEY variable:

EASY_MAPS_GOOGLE_MAPS_API_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)

To use a custom geocoder set the EASY_MAPS_GEOCODE option:

# Default: 'easy_maps.geocode.google_v3'
EASY_MAPS_GEOCODE = 'example.custom_geocode'

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.4 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


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.9.4.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

django_easy_maps-0.9.4-py2.py3-none-any.whl (15.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django-easy-maps-0.9.4.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for django-easy-maps-0.9.4.tar.gz
Algorithm Hash digest
SHA256 b51648d619183c5b5550d93ec2ee55c1ae9fc55f6151e883de2a716a6ebae47b
MD5 04a46c9e3f6171f2290b0d4ddb906122
BLAKE2b-256 12e1511ac4ef814f64977efa06f0fb52c6de24444cc8948321068e95f72a5bc1

See more details on using hashes here.

Provenance

File details

Details for the file django_easy_maps-0.9.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_easy_maps-0.9.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 df69003a30676d9ecdb66d40c0f923b53bd92ac0c33c00286437f52d8b06c063
MD5 a9964b28bd843ee89da08e4b71751c8d
BLAKE2b-256 bd639017a65819ad3e7a0e7117dfdb511b5c3bea34f917fa18464531f6f206f8

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page