Skip to main content
 首页 » 编程设计

python之Django django-location-field 缺少 API key

2025年02月15日25xing901022

我正在使用 https://github.com/caioariede/django-location-field使用 Django 构建位置 View 的库。问题是我找不到说明如何定义我自己的 Google Maps API KEY 的文档。

这是我的 settings.py 中的代码:

LOCATION_FIELD_PATH = STATIC_URL + 'location_field' 
LOCATION_FIELD = { 
    'map.provider': 'google', 
    'map.zoom': 13, 
 
    'search.provider': 'google', 
    'search.suffix': '', 
 
    # Google 
    'provider.google.api': '//maps.google.com/maps/api/js', 
    'provider.google.api_key': 'MY_API_KEY_HERE', 
    'provider.google.map_type': 'ROADMAP', 
 
 
    # misc 
    'resources.root_path': LOCATION_FIELD_PATH, 
    'resources.media': { 
        'js': [ 
           LOCATION_FIELD_PATH + '/js/jquery.livequery.js', 
            LOCATION_FIELD_PATH + '/js/form.js', 
        ], 
    }, 
} 

但这个解决方案似乎不起作用。

maps.google.com/maps-api-v3/api/js/28/11/util.js:219 Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys 

我已经搜索了一段时间,但没有找到答案。

请您参考如下方法:

您可以使用 django-geoposition而不是 django-location-field .它具有相同的功能,并且还有一个简单的文档 https://django-geoposition.readthedocs.io/en/latest/ .

您可以在 https://django-geoposition.readthedocs.io/en/latest/#installation 中找到如何定义您的 Google map API key 。 .