from django import template from django.conf import settings register = template.Library() class GoogleMapNode(template.Node): def __init__(self,postcode='',xandy='',zoom=14): self.postcode = template.Variable(postcode.strip("\"")) self.x, self.y = xandy.strip('"').split('x') self.zoom = template.Variable(zoom) def render(self,context): error = [] if not hasattr(settings, 'GOOGLE_MAPS_API_KEY'): error.append('Google maps api not found') if not hasattr(settings, 'GOOGLE_AJAX_API_KEY'): error.append('Google ajax key not found') postcode = self.postcode.resolve(context) try: zoom = int(self.zoom.resolve(context)) except: error.append('Zoom must be an integer') answer = '' % settings.GOOGLE_MAPS_API_KEY answer += '' % settings.GOOGLE_AJAX_API_KEY answer += '' % postcode answer += '' % zoom answer += '' % settings.MEDIA_URL answer += '
' % (self.x,self.y) if error: return ', '.join(error) return answer @register.tag def googlemap_from_ukpostcode(parser,token): bits = token.contents.split() if len(bits) == 3: return GoogleMapNode(postcode=bits[1],xandy=bits[2]) elif len(bits) == 4: return GoogleMapNode(postcode=bits[1],xandy=bits[2],zoom=bits[3]) else: raise template.TemplateSyntaxError("'%s' tag takes two or three arguments, postcode, x/y size of map (e.g. \"100x200\") and zoom level" % bits[0]) ============= google_map_ukpostcodes.js var map; var localSearch = new GlocalSearch(); var icon = new GIcon(); icon.image = "http://www.google.com/mapfiles/marker.png"; icon.shadow = "http://www.google.com/mapfiles/shadow50.png"; icon.iconSize = new GSize(20, 34); icon.shadowSize = new GSize(37, 34); icon.iconAnchor = new GPoint(10, 34); function usePointFromPostcode(postcode, callbacks) { localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat,resultLng); for (var i=0;i