Я написал скрипт, который может использовать историю местоположений из Google и вывести ее на веб-сайт hmtl:
import json
from datetime import datetime
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, GMapOptions
from bokeh.plotting import gmap
#place your history file in your project deirectory
with open("Standortverlauf.json") as f:
data = json.load(f)
print("JSON Load Successfull!")
lats = []
longs = []
#retrieving the lats and longs
for entry in data["locations"]:
ts = int(entry["timestampMs"][:10])
time = datetime.utcfromtimestamp(ts)
# place your start date as unix timestamp below
if int(entry["timestampMs"][:10]) > 1554336000:
lats.append(entry["latitudeE7"]/(10**7))
longs.append(entry["longitudeE7"]/(10**7))
print(len(lats))
output_file("gmap.html")
map_options = GMapOptions(lat=37.81, lng=-122.45, map_type="roadmap", zoom=12)
# For GMaps to function, Google requires you obtain and enable an API key:
# https://developers.google.com/maps/documentation/javascript/get-api-key
# or: https://console.cloud.google.com/apis/credentials?project=hybrid-zephyr-271316 "Anmeldedaten", "Anmeldedaten erstellen", "API-Schlüssel erstellen"
# Replace the value below with your personal API key
p = gmap("API key", map_options, title="Location History",
tools = "box_zoom, pan, wheel_zoom", width=1500, height=700)
source = ColumnDataSource(
data=dict(lat=lats,
lon=longs)
)
# change color and size of the dots below
p.circle(x="lon", y="lat", size=6, fill_color="red", fill_alpha=0.8, source=source)
#This adds lines but can take much longer
p.multi_line(x='lon', y='lat', source=source, color='red', line_width=3)
show(p)
Код отлично работает, кроме строки multi_line, которая приводит к следующей ошибке:
JSON Load Successfull!
6373
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-d49b67550055> in <module>
48 p.circle(x="lon", y="lat", size=6, fill_color="red", fill_alpha=0.8, source=source)
49 #This adds lines but can take much longer
---> 50 p.multi_line(x='lon', y='lat', source=source, color='red', line_width=3)
51 show(p)
TypeError: multiline() missing 2 required positional arguments: 'xs' and 'ys'
Можете ли вы помочь мне, как я могу отладить линию и соединить линии между моими точками?
Спасибо за вашу помощь!