使用 google 映射 api 和 python

using google maps api with python

我正在按照 this 指南开始使用 gmaps api 和 python;

import gmaps
import gmaps.datasets
import pandas as pd


def func():
    # Use google maps api
    gmaps.configure(api_key='MY_API_KEY')  # Fill in with your API key
    # Get the dataset
    earthquake_df = gmaps.datasets.load_dataset_as_df('earthquakes')
    # Get the locations from the data set
    locations = earthquake_df[['latitude', 'longitude']]
    # Get the magnitude from the data
    weights = earthquake_df['magnitude']
    # Set up your map
    fig = gmaps.figure()
    fig.add_layer(gmaps.heatmap_layer(locations, weights=weights))
    return fig

func()

一直在使用指南中的这段代码(在 pychram 和 jupyter 笔记本上),但是当我 运行 代码 (pychram/jupyter/terminal) 时,我没有像指南中那样得到输出映射。 只是一个不错的老式

Process finished with exit code 0

首先通过 运行ning jupyter nbextension list 检查是否为 jupyter 启用了它。 如果您没有看到 jupyter-gmaps/extension enabled,那么您需要在终端 jupyter nbextension enable --py gmaps 中 运行 这一行,然后 运行 一个新的 jupyter notebook。