Allow usage of a Google Maps API KEY with BaseGMapWidget #174

merged 1 commit into from Aug 15, 2016


None yet

2 participants

victor-o-silva commented Aug 14, 2016 edited

Since June 2016, Google Maps API requires an API Key, otherwise the maps may fail to load:


This PR gives developers the ability to supply their API Keys to the Google Maps API by setting the attribute google_maps_api_key in BaseGMapWidget subclasses:

class GMapPolygonWidget(forms.gis.BaseGMapWidget, forms.gis.PolygonWidget):
    google_maps_api_key = 'YOUR-GOOGLE-MAPS-API-KEY-HERE'



  • Made the form's media dynamic by defining it as a property instead of a static class
  • Stopped the escaping of ampersands in the gmaps script url, for it was being rendered like this: (...)js?v=3&sensor=false
  • Removed sensor parameter, for it's no longer required
  • Appended key parameter if API Key is set


  • To keep the docs simple, used BaseOsmWidget instead of BaseGMapWidget in most examples, because BaseGMapWidget now requires a special attribute
  • Documented BaseGMapWidget.google_maps_api_key and put a link to where developers can obtain the Google Maps API Key
  • Fixed a minor typo

Travis failed before the tests even started:

mv: cannot stat `/etc/apt/sources.list.d/pgdg-source.list_': No such file or directory
The command "sudo mv /etc/apt/sources.list.d/pgdg-source.list_ /tmp" failed and exited with 1

@gregmuellegger gregmuellegger commented on the diff Aug 15, 2016
@@ -259,6 +270,7 @@ widget):
.. code-block:: python
+ from django.template.defaultfilters import safe
gregmuellegger Aug 15, 2016 Owner

safe is meant to be used as a filter in the template. I think we can use django.utils.html.mark_safe here instead.

@gregmuellegger gregmuellegger commented on the diff Aug 15, 2016
@@ -1,7 +1,14 @@
from django.conf import settings
+from django.template.defaultfilters import safe
gregmuellegger Aug 15, 2016 Owner

We should use mark_safe here as well.


That is great work! Thanks for the investigation and PR. I'll test the changes locally and will then get it merged and released.

@gregmuellegger gregmuellegger merged commit 16cc283 into gregmuellegger:master Aug 15, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
@gregmuellegger gregmuellegger added a commit that referenced this pull request Aug 15, 2016
@gregmuellegger Add changelog for #174 134038f

Merged and released as 1.7.0:

@victor-o-silva victor-o-silva deleted the victor-o-silva:gmap_api_key branch Aug 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment