from bottle import route, request, run
map_html = ''
file_path = ''
@route('/')
@route('/map')
def map_view():
return map_html
@route('/pos')
def pos_api():
last_line = ''
try:
nmea_file = open(file_path,'r',encoding='utf8')
while True:
try:
temp_line = nmea_file.readline()
if temp_line:
if temp_line.startswith("$GPGGA"):
last_line = temp_line
else:
break
except:
pass
nmea_file.close()
except:
return ''
if last_line.startswith("$GPGGA"):
l = last_line.split(',')
if len(l)<7:
return ''
tow = float(l[1])
lat = l[2]
lon = l[4]
if not lat or not lon:
return ''
lat = int(lat[:2])+float(lat[2:])/60
lon = int(lon[:3])+float(lon[3:])/60
position = {'lat': lat ,'lon': lon, 'tow': tow}
callback = request.query.callback
import json
return '%s(%s)' % (callback,json.dumps(position))
else:
return ''
import sys, os, webbrowser, threading, time
if __name__ == '__main__':
if len(sys.argv)>1:
file_path = sys.argv[1]
else:
file_path = input('Please input nmea file path below:\n')
file_path = os.path.abspath(file_path)
try:
map_file = open(os.path.join(os.path.split(os.path.realpath(sys.argv[0]))[0],'map.html'),'r',encoding='utf8')
map_html = map_file.read()
t1 = threading.Thread(target=lambda : run(host='0.0.0.0', port=8000, quiet=True))
t2 = threading.Thread(target=lambda : webbrowser.open("http://127.0.0.1:8000"))
t1.start()
time.sleep(3)
t2.start()
print('')
print('#############################')
print('# OK, it started to work! #')
print('#############################')
except:
pass
amap-bottle.py.tar.gz_python 高德地图_高德地图_高德路线
版权申诉
170 浏览量
2022-09-23
17:49:14
上传
评论
收藏 853B GZ 举报
JonSco
- 粉丝: 66
- 资源: 1万+