・緯度経度を取得するプログラム
・緯度経度を指定してマーカーをプロットするプログラム
これらを組み合わせて、リアルタイムで緯度経度を取得したあと、その緯度経度を基に地図上にプロットしたい
(なんとなく二個目のプログラム内において配列に格納されている要素(この緯度経度情報を地図上にマーカーで表す)に一個目のプログラムで取得できた緯度経度を当てはめればできると思ったのですがやり方がわかりませんでした。。)
【プログラム①】--------------------------------------------------------
Python
1import serial 2import micropyGPS 3import threading 4import time 5 6gps = micropyGPS.MicropyGPS(9, 'dd') # MicroGPSオブジェクトを生成する。 7 # 引数はタイムゾーンの時差と出力フォーマット 8 9def rungps(): # GPSモジュールを読み、GPSオブジェクトを更新する 10 s = serial.Serial('/dev/serial0', 9600, timeout=10) 11 s.readline() # 最初の1行は中途半端なデーターが読めることがあるので、捨てる 12 while True: 13 sentence = s.readline().decode('utf-8') # GPSデーターを読み、文字列に変換する 14 if sentence[0] != '$': # 先頭が'$'でなければ捨てる 15 continue 16 for x in sentence: # 読んだ文字列を解析してGPSオブジェクトにデーターを追加、更新する 17 gps.update(x) 18 19gpsthread = threading.Thread(target=rungps, args=()) # 上の関数を実行するスレッドを生成 20gpsthread.daemon = True 21gpsthread.start() # スレッドを起動 22 23while True: 24 if gps.clean_sentences > 20: # ちゃんとしたデーターがある程度たまったら出力する 25# h = gps.timestamp[0] if gps.timestamp[0] < 24 else gps.timestamp[0] - 24 26# print('%2d:%02d:%04.1f' % (h, gps.timestamp[1], gps.timestamp[2])) 27 print('緯度経度: %2.8f, %2.8f' % (gps.latitude[0], gps.longitude[0])) 28# print('海抜: %f' % gps.altitude) 29# print(gps.satellites_used) 30# print('衛星番号: (仰角, 方位角, SN比)') 31# for k, v in gps.satellite_data.items(): 32# print('%d: %s' % (k, v)) 33# print('') 34 time.sleep(1.0) 35 36
【プログラム②】--------------------------------------------------------
Python
1import folium 2 3latitudes = [35.31225167,35.31214500] #配列にする 4longtudes = [139.62736833,139.62731333] 5 6map = folium.Map(location=[latitudes[0], longtudes[0]], zoom_start=18) 7 8for latitude, longtude in zip(latitudes,longtudes): 9 folium.Marker(location=[latitude, longtude], icon=folium.Icon(color='black', icon='circle')).add_to(map) 10 11map.save("marks2.html")
回答1件
あなたの回答
tips
プレビュー