How to specify API key in Google Cloud Datalab map Google Chart?
很高兴了解 Google Charts 和 Cloud Datalab。遇到这个需要 API 密钥并且无法确定如何将其传递给库的示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | %%sql --module taxi DEFINE QUERY locations SELECT FLOAT(pickup_latitude) AS lat, FLOAT(pickup_longitude) AS lon, medallion FROM [833682135931:nyctaxi.trip_data] DEFINE QUERY geohashes SELECT lat, lon, CONCAT(STRING(FLOOR(lat*1000+0.5)/1000), ':', STRING(FLOOR(lon*1000+0.5)/1000)) AS geoid, medallion FROM $locations WHERE lat != 0 AND lon != 0 DEFINE QUERY hotspots SELECT FIRST(lat) AS lat, FIRST(lon) AS lon, COUNT(medallion) AS pickups FROM $geohashes WHERE ABS(HASH(medallion)) % 1000 == 1 GROUP BY geoid ORDER BY pickups DESC LIMIT 25 |
新单元格:
1 2 3 4 | %%chart map --fields lat,lon,pickups --data taxi.hotspots showTip: true mapType: normal key: {my-key-here} # <- just my guess at how to specify the key |
不用说这不起作用。最初它抛出了一个错误,但现在它完成并在图表应该存在的地方留下了一个空白区域。
应如何在 Google Cloud Datalab 单元格中指定它们?
需要在笔记本的 Javascript 全局命名空间中指定密钥。在运行地图单元之前在一个单元中运行它:
1 2 | %%html <script src="https://maps.googleapis.com/maps/api/js?key=<YOUR_API_KEY>&callback=initMap" async defer> |