pbugnion / gmaps

Google maps for Jupyter notebooks
https://jupyter-gmaps.readthedocs.io/en/stable/
Other
760 stars 146 forks source link

How to add a point on Google Map using python's gmaps? #336

Open rahulbhadani opened 4 years ago

rahulbhadani commented 4 years ago

I am trying to add a Point on Google Map in Jupyter Notebook as follows:

import gmaps
API_Key = 'CJJUIIEaSyBpv6a' # This is not the legit key, I have not provided a real API key to avoid misuse and for security reasons
gmaps.configure(api_key=API_Key)
centroid_lat, centroid_long = (82.301581497344834, 110.89898182803991)
center_coordinates = (centroid_lat, centroid_long)
fig = gmaps.figure(center=center_coordinates, zoom_level=13.5)

P = gmaps.Point(center_coordinates)
point_layer = gmaps.drawing_layer(features=[P])
fig.add_layer(point_layer)
fig

However, I am getting following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-35-baba23e890bf> in <module>
     10 #driving_layer = gmaps.heatmap_layer(coordinates)
     11 P = gmaps.Point(center_coordinates)
---> 12 point_layer = gmaps.drawing_layer(features=[P])
     13 fig.add_layer(driving_layer)
     14 fig
.
.
.

~/anaconda3/envs/dbn/lib/python3.7/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    195 
    196     # we don't understand it, it's probably an unserializable object
--> 197     raise ValueError("Can't clean for JSON: %r" % obj)

ValueError: Can't clean for JSON: <gmaps.geotraitlets.Point object at 0x7fb6f1e3a490>

I don't understand error fully. Please help, if you have experience on using gmaps.

Thanks.