Login

Tag "google-maps"

Snippet List

Google v3 geocoding for Geodjango admin site

This only works with Point geometry. [video](http://www.youtube.com/watch?v=gZ7_n177sTE&list=HL1351725584&feature=mh_lolz) Rename the snippet as gmgdav3.js and save it to template/admin with [gmgdav3.html](http://djangosnippets.org/snippets/2840/) * - *models.py*: ` from django.contrib.gis.db import models` ` class point(models.Model):` ` address = models.CharField(max_length=100, help_text='Press "Tab" to refresh the map')` ` longitude = models.FloatField(help_text='WGS84 Decimal Degree. Press "Tab" to refresh the map')` ` latitude = models.FloatField(help_text='WGS84 Decimal Degree. Press "Tab" to refresh the map')` ` in_geom = models.PointField('shp', srid=4326)` ` objects = models.GeoManager()` ` def __unicode__(self):` ` return str(self.address)` * - *admin.py*: ` from models import * ` ` from django.conf import settings` ` from django.contrib.gis import admin` ` from django.contrib.gis.geos import GEOSGeometry` ` class GoogleAdmin(admin.OSMGeoAdmin):` ` g = GEOSGeometry('POINT (9.191884 45.464254)') # Set map center` ` g.set_srid(4326)` ` g.transform(900913)` ` default_lon = int(g.x)` ` default_lat = int(g.y)` ` default_zoom = 7` ` extra_js = ["http://maps.google.com/maps/api/js?v=3.2&sensor=false"]` ` map_template = 'gmgdav3.html'` ` admin.site.register(point, GoogleAdmin)` ` # admin.site.register(your other models...,...)`

  • admin
  • google-maps
  • geocode
  • geolocation
  • geodjango
Read More

KMLMiddleware

This is a slight modification from the original version at [http://djangosnippets.org/snippets/709/](http://djangosnippets.org/snippets/709/) and is a middleware designed to output the right headers for generated KML or KMZ content. In the case of KMZ content, it handles the compression of the original KML content into the KMZ format. This version applies the processing to only requests ending with a .kml or .kmz in the URL. For instance, a request with the URL **http://example.com/kml/foo.kml** or **http://example.com/foo.kmz** will get processed by this middleware.

  • google-maps
  • kml
  • kmz
  • google-earth
Read More

Google Maps Templatetag

Use: ... <head> ... {% gmap-script %} ... </head> ... <body> ... {% gmap name:mimapa width:300 height:300 latitude:x longitude:y zoom:20 view:hybrid %} Message for a marker at that point {% endgmap %} ... </body>

  • templatetag
  • google-maps
  • maps
Read More

Google Geocode Lookup

Makes a call to Google's geocoder and returns the latitude and longitude as a string or returns an empty string. Called by the save method to save the lat and long to the db to be used when rendering maps on the frontend. Reduces the number of calls to geocoder by calling only when saving, not on every viewing of the object. Be sure to import *urllib* and the project's *settings*, and to define GOOGLE_API_KEY in settings.py. **Example:** def save(self): location = "%s+%s+%s+%s" % (self.address, self.city, self.state, self.zip_code) self.lat_long = get_lat_long(location) if not self.lat_long: location = "%s+%s+%s" % (self.city, self.state, self.zip_code) self.lat_long = get_lat_long(location) super(Foo, self).save()

  • google-maps
  • geocode
  • google-api
  • latitude
  • longitude
Read More

5 snippets posted so far.