Python django.conf.settings 模块,GOOGLE_MAPS_API_KEY 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.conf.settings.GOOGLE_MAPS_API_KEY

项目:organizer    作者:tdfischer    | 项目源码 | 文件源码
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]
项目:lenuage    作者:laboiteproject    | 项目源码 | 文件源码
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')
项目:mes    作者:osess    | 项目源码 | 文件源码
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))
项目:mes    作者:osess    | 项目源码 | 文件源码
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,
    }