Harry
Harry

Reputation: 51

How to create a google map in jupyter notebook using Latitude and Longitude

    import gmaps
    import gmaps.datasets
    gmaps.configure(api_key="AI...") # Your Google API key

    locations = gmaps.datasets.load_dataset("starbucks_uk")

   fig = gmaps.Map()
    starbucks_layer = gmaps.symbol_layer(
        locations, fill_color="green", stroke_color="green", scale=2)
    fig.add_layer(starbucks_layer)
    fig

I am currently trying to load this in my jupyter notebook, however the map will not display

Any help on this would be appreciated!

Upvotes: 3

Views: 6650

Answers (1)

Imran273
Imran273

Reputation: 431

first, You need to write this code in your terminal:

jupyter nbextension enable --py gmaps

and then make sure in your terminal you get "validating ok" in your terminal.

for the datasets itself, you need to write 'starbucks_kfc_uk' not "starbucks_uk"

next code should be like this:

starbucks_df = df[df['chain_name'] == 'starbucks']
starbucks_df = starbucks_df[['latitude', 'longitude']]

starbucks_layer = gmaps.symbol_layer(
    starbucks_df, fill_color="green", stroke_color="green", scale=2
)
fig = gmaps.figure()
fig.add_layer(starbucks_layer)
fig

And this is my result:

enter image description here

Upvotes: 3

Related Questions