Login

GoogleAdmin: GMaps base layer in Geographic Admin (GeoDjango)

Author:
jbronn
Posted:
October 15, 2008
Language:
Python
Version:
1.0
Score:
3 (after 3 ratings)

This GeoDjango subclass substitutes in the Google Maps base layer instead of the default one provided by Open Street Map. Requires the google.html and google.js templates (must be placed in gis/admin somewhere in your template path).

Requires a Google Maps API key -- please abide by Google's terms of service.

1
2
3
4
5
6
7
8
from django.contrib.gis import admin
from django.contrib.gis.maps.google import GoogleMap

GMAP = GoogleMap(key='abcdefg') # Can also set GOOGLE_MAPS_API_KEY in settings

class GoogleAdmin(admin.OSMGeoAdmin):
    extra_js = [GMAP.api_url + GMAP.key]
    map_template = 'gis/admin/google.html'

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

marxy (on August 4, 2009):

This works but unfortunately when I save I get a validation error "An error occurred when transforming the geometry to the SRID of the geometry form field".

In my case the Model contains a Point.

Any tips would be appreciated.

#

andriy (on June 29, 2012):

Can anyone help where to put this code (is it models.py)???

from django.contrib.gis import admin from django.contrib.gis.maps.google import GoogleMap

GMAP = GoogleMap(key='abcdefg') # Can also set GOOGLE_MAPS_API_KEY in settings

class GoogleAdmin(admin.OSMGeoAdmin): extra_js = [GMAP.api_url + GMAP.key] map_template = 'gis/admin/google.html'

#

andriy (on June 30, 2012):

Can anyone provide a more detailed description on how to enable Google Maps in admin site, I'm knew to Django

#

Please login first before commenting.