Google Maps API在虚拟环境中

时间:2019-01-04 05:53:44

标签: python-3.x google-maps google-oauth

在虚拟环境中使用Google Maps API密钥是否有窍门?尝试访问我的Maps API密钥时出现“密钥错误”。

Maps API key error

我的API受到限制,仅允许HTTP引荐来源网址。我已经对计算机进行了Google Cloud身份验证(可以访问Google DataStore)。

这是我在Python中运行的代码。我正在使用Bokeh生成情节。

def location(request):
import os
from bokeh.models import GMapOptions
from bokeh.plotting import gmap

client = datastore.Client()
query = client.query(kind='locData')
query.order = ['-ts']
resultList = list(query.fetch())
i = 0
lat = []
lng = []
for each in resultList:
    lat.append(each['lat'])
    lng.append(each['lng'])
    i += 1
result = i
data = dict(lat=lat, lng=lng)

title = "Location"
plot = figure(title = title,
    plot_width = 400,
    plot_height = 400)

map_options = GMapOptions(lat=45, lng=-118, map_type='roadmap', zoom=11)
api_key = os.environ['... key hidden ...'] 

plot = gmap(api_key, map_options, title="Travels")
plot.circle(x='lng', y='lat', size=15, fill_color='blue',fill_alpha=0.8, source=data)

#store components
script, div = components(plot)

#feed components to django template
return render_to_response('dashboard/singleplot.html',
    {
        'script': script,
        'div': div,
        'date': datetime.now(),
        'data': result
    }
)

0 个答案:

没有答案