我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.conf.settings.GOOGLE_MAPS_API_KEY。
def address_from_row(row): geocoder = GoogleV3(settings.GOOGLE_MAPS_API_KEY) addr_to_geocode = "" if 'full_address' in row and len(row['full_address']) > 0: addr_to_geocode = row['address'] elif 'zipcode' in row and len(row['zipcode']) > 0: addr_to_geocode = row['zipcode'] elif 'city' in row and len(row['city']) > 0: addr_to_geocode = row['city'] if addr_to_geocode is None: logging.debug("Could not find suitable geocode field") return None if addr_to_geocode not in __addr_cache: geocoded = None try: geocoded = geocoder.geocode(addr_to_geocode) except: pass if geocoded: ret = translate_google_result(geocoded.raw) __addr_cache[addr_to_geocode] = ret else: __addr_cache[addr_to_geocode] = addr_to_geocode logging.debug("%s -> %r", addr_to_geocode, __addr_cache[addr_to_geocode]) return __addr_cache[addr_to_geocode]
def update_data(self): params = {'origin': self.start, 'destination': self.dest, 'mode': self.mode, 'key': settings.GOOGLE_MAPS_API_KEY} r = requests.get(settings.GOOGLE_MAPS_BASE_URL, params=params) routes = r.json().get('routes') all_routes = [] for route in routes: duration = sum(leg['duration']['value'] for leg in route['legs']) // 60 all_routes.append({'trajectory_name': route['summary'], 'trip_duration': duration}) if all_routes: all_routes.sort(key=lambda route: route['trip_duration']) best_route = all_routes.pop(0) self.trajectory_name = best_route['trajectory_name'] self.trip_duration = best_route['trip_duration'] self.save() else: raise ExternalDataError('No route found')
def homepage(request, template_name="homepage_mes.html"): real_ip = None; geo = None try: real_ip = request.META['HTTP_X_FORWARDED_FOR'] except: pass if request.user.is_authenticated(): template_name ="dashboard.html" return render_to_response(template_name, { # "GOOGLE_MAPS_API_KEY": settings.GOOGLE_MAPS_API_KEY, # "geo": geo, # "real_ip":real_ip, }, context_instance=RequestContext(request))
def start(request): #g = GeoIP() real_ip = None; geo = None try: real_ip = request.META['HTTP_X_FORWARDED_FOR'] #real_ip = request.META['REMOTE_ADDR'] except: #real_ip = '82.197.131.84' pass #if real_ip != None: # geo = g.city(real_ip) #geo = None if geo == None: geo = {'latitude': 37.4419, 'longitude': 122.1419, 'city': 'Shanghai', 'country_name': 'New Zealand'} return { "version": settings.VERSION, #"GOOGLE_MAPS_API_KEY": settings.GOOGLE_MAPS_API_KEY, "geo": geo, }