Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install m01.gmap

How to install m01.gmap

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install m01.gmap
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
0.6.1 Available View build log
Linux (32-bit)
0.6.1 Available View build log
Linux (64-bit)
0.6.1 Available View build log
ZPL 2.1
Lastest release
version 0.6.1 on Jul 3rd, 2013

This package provides a m01.mongo and z3c.form based google map widget for Zope3.


This package provides a z3c.form widget concept for google maps. For more info about google maps see: http://code.google.com/apis/maps/.

The google map (GMapWidget) widget allows you to show a map for select latitude and longitude for a geo location in input mode. In display mode it offers a GMap which shows the given location.

As for all widgets, the GMap widget must provide the IWidget interface:

>>> from zope.interface.verify import verifyClass
>>> from z3c.form.interfaces import IWidget
>>> from z3c.form.interfaces import INPUT_MODE
>>> from m01.gmap.widget import GMapWidget
>>> verifyClass(IWidget, GMapWidget)

The widget can be instantiated only using the request:

>>> from z3c.form.testing import TestRequest
>>> request = TestRequest()
>>> widget = GMapWidget(request)

Before rendering the widget, one has to set the name and id of the widget:

>>> widget.id = 'widget.id'
>>> widget.name = 'widget.name'

We also need to register the template for the widget:

>>> import zope.component
>>> from zope.pagetemplate.interfaces import IPageTemplate
>>> from z3c.form.widget import WidgetTemplateFactory
>>> import os
>>> import m01.gmap
>>> def getPath(filename):
...     return os.path.join(os.path.dirname(m01.gmap.__file__),
...     filename)
>>> from m01.gmap import interfaces
>>> zope.component.provideAdapter(
...     WidgetTemplateFactory(getPath('widget_input.pt'), 'text/html'),
...     (None, None, None, None, interfaces.IGMapWidget),
...     IPageTemplate, name=INPUT_MODE)

If we render the widget we get a simple input element:

>>> print(widget.render())
<input type="hidden" id="widget.id-latitude" name="widget.name-latitude" class="hidden-widget" value="" />
<input type="hidden" id="widget.id-longitude" name="widget.name-longitude" class="hidden-widget" value="" />
<div id="widget.id" style="width: 400px; height: 300px"></div>
<script type="text/javascript">
    iconWidth: 19,
    infoWindowAnchorYOffset: 0,
    iconHeight: 32,
    iconURL: "",
    iconAnchorXOffset: 9,
    zoomFallback: 4,
    zoom: 11,
    longitude: null,
    longitudeFallback: 10,
    latitudeFallback: 10,
    latitudeExpression: "#widget\\.id-latitude",
    mode: "input",
    infoWindowContent: "Drag and drop the marker and save the form. <br />Double click the marker for remove them.",
    address: "",
    latitude: null,
    iconAnchorYOffset: 30,
    longitudeExpression: "#widget\\.id-longitude",
    iconShadowURL: "",
    infoWindowAnchorXOffset: 10

We also need to include the IGMapAPIProvider wcih knows how to generate the gamp api javascipt. The APi key it'self can get defined with a product config or with a envirnoment setup. See buildout.cfg and util.py for more info:

>>> import m01.gmap.util
>>> m01.gmap.util.GMAP_API_KEY

We offer http or https javascript links:

>>> print(m01.gmap.util.GMAP_JAVASCRIPT)
<script type="text/javascript" src="//maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAFAsu6H_TCNEapjedv-QILxTwM0brOpm-All5BF6PoaKBxRWWERQwU76rKRQO6OVZmsjxrqya2hcEBw"> </script>
>>> print(m01.gmap.util.GMAP_HTTPS_JAVASCRIPT)
<script type="text/javascript" src="https://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAFAsu6H_TCNEapjedv-QILxTwM0brOpm-All5BF6PoaKBxRWWERQwU76rKRQO6OVZmsjxrqya2hcEBw"> </script>

And you content provider can get used for render the full javascript:

>>> import m01.gmap.browser
>>> provider = m01.gmap.browser.GMapAPIProvider(None, None, None)
>>> print(provider.render())
<script type="text/javascript" src="https://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAFAsu6H_TCNEapjedv-QILxTwM0brOpm-All5BF6PoaKBxRWWERQwU76rKRQO6OVZmsjxrqya2hcEBw"> </script>


0.6.1 (28-06-2013)
  • bugfix: fix lat, lng setup in gmaps v3 api javascript
0.6.0 (2013-01-04)
  • update to google maps api v3
0.5.0 (2012-11-18)
  • initial release

Subscribe to package updates

Last updated Jul 3rd, 2013

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.