1. Mikhail Korobov
  2. django-easy-maps


Daniel Greenfeld  committed d2daaec

Adding Google API key to help when you get blocked

  • Participants
  • Parent commits 946bb6f
  • Branches default

Comments (0)

Files changed (2)

File README.rst

View file
  • Ignore whitespace
 Then add 'easy_maps' to INSTALLED_APPS and run ``./manage.py syncdb``
 (or ``./manage.py migrate easy_maps`` if South is in use)
+If working on localhost you can run into Google Maps API lockdown. If this happens
+then create a EASY_MAPS_GOOGLE_KEY in your settings.py file::
+    EASY_MAPS_GOOGLE_KEY = "your-google-maps-api-key"

File easy_maps/models.py

View file
  • Ignore whitespace
+from django.conf import settings
 from django.db import models
 from django.utils.encoding import smart_str
 from geopy import geocoders
             self.geocode_error = True
-            g = geocoders.Google(resource='maps')
+            if hasattr(settings, "EASY_MAPS_GOOGLE_KEY"):
+                g = geocoders.Google(settings.EASY_MAPS_GOOGLE_KEY)
+            else:
+                g = geocoders.Google(resource='maps')
             address = smart_str(self.address)
             self.computed_address, (self.latitude, self.longitude,) = g.geocode(address)
             self.geocode_error = False