Package: django-easy-maps
django-easy-mapsThis app makes it easy to display a map for any given address indjangotemplates. No manual geocoding, html/js copy-pasting or Django
model changes are needed.Authored byMikhail Korobov, and some greatcontributors.InstallationFirst install the module, preferably in a virtual environment. It can be installed from PyPI:pipinstalldjango-easy-mapsSetupYou’ll need to addeasy_mapstoINSTALLED_APPSin your project’ssettings.pyfile:INSTALLED_APPS+=['easy_maps',]Then run./manage.py migrateto create the required database tables.ConfigurationThe only mandatory configuration is theEASY_MAPS_GOOGLE_KEYvariable: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 theEASY_MAPS_CENTERvariable in
yoursettings.pylike the following:EASY_MAPS_CENTER=(-41.3,32)Other optional settings:# OptionalEASY_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 theexampleapplication. 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.UsageFirst of all, load theeasy_map_tagsin every template where you want to use it:{%loadeasy_maps_tags%}Use:{%easy_map<address>[<width><height>][<zoom>][using<template_name>]%}For example:{%loadeasy_maps_tags%}<!-- Default map with 300x400 dimensions -->{%easy_map"Russia, Ekaterinburg, Mira 32"300400%}<!-- Variable address, custom detail level and custom template -->{%easy_mapaddress2002005using"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:{%loadeasy_maps_tagscache%}{%cache600my_mapfirm.address%}{%easy_mapfirm.address300400%}{%endcache%}TemplatesIf the default map template is not sufficient then a custom map template can be
used. For example:{%easy_mapaddressusing"map.html"%}{%easy_mapaddress2003005using"map.html"%}The template will havemap(easy_maps.Addressinstance
auto-created for passed address on first access),width,heightandzoomvariables. 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 tohttps://developers.google.com/maps/documentation/javascript/for
detailed Google Maps JavaScript API help.Widgetsdjango-easy-mapsprovides a basic widget that displays a map under the address
field. It can be used in the admin for map previews. For example:fromdjangoimportformsfromdjango.contribimportadminfromeasy_maps.widgetsimportAddressWithMapWidgetfrom.modelsimportFirmclassFirmAdmin(admin.ModelAdmin):classform(forms.ModelForm):classMeta:widgets={'address':AddressWithMapWidget({'class':'vTextField'})}admin.site.register(Firm,FirmAdmin)addressfield should be either aCharFieldorTextField.ContributingIf 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!Licensedjango-easy-mapsis released under the MIT license.