show distance to destination, and icon

This commit is contained in:
rgarcia-herrera 2020-08-11 16:59:55 -05:00
parent 44777805b2
commit 3b62936b2a
4 changed files with 23 additions and 8 deletions

View File

@ -36,7 +36,7 @@ version = 0.1
# (list) Application requirements # (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy # comma separated e.g. requirements = sqlite3,kivy
requirements = hostpython3, python3, kivy, plyer, android, mapview, requests, urllib3, chardet, idna requirements = hostpython3, python3, kivy, plyer, android, mapview, requests, urllib3, chardet, idna, geopy, geographiclib
# (str) Custom source folders for requirements # (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes # Sets custom source for any requirements with recipes
@ -49,7 +49,7 @@ requirements = hostpython3, python3, kivy, plyer, android, mapview, requests, ur
presplash.filename = ./presplash.png presplash.filename = ./presplash.png
# (str) Icon of the application # (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png icon.filename = ./icon.png
# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all) # (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
orientation = portrait orientation = portrait

View File

@ -21,7 +21,7 @@
ActionButton: ActionButton:
important: False important: False
text: 'go to current loc' text: 'go to current loc'
on_press: app.center_map_on_gps() on_press: app.center_map_on_gps()
ActionButton: ActionButton:
important: True important: True
text: 'we ride together' text: 'we ride together'
@ -58,13 +58,18 @@
important: True important: True
text: 'set destination' text: 'set destination'
on_press: root.manager.current = 'map'; on_press: root.manager.current = 'map';
FloatLayout: FloatLayout:
canvas: canvas:
Color: Color:
rgb: .9, .9, .9 rgb: .9, .9, .9
Rectangle: Rectangle:
size: self.size size: self.size
Label:
text: app.dest_distance
color: 0, 0, 0.3, 1
size_hint: 0.5, 0.1
pos: 0, 0.1
font_size: '40sp'
Image: Image:
source: 'needle.png' source: 'needle.png'
canvas.before: canvas.before:
@ -76,7 +81,7 @@
canvas.after: canvas.after:
PopMatrix PopMatrix
Image: Image:
id: to_flock id: to_flock
source: 'needle_to_flock.png' source: 'needle_to_flock.png'
canvas.before: canvas.before:
PushMatrix PushMatrix

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

16
main.py
View File

@ -1,7 +1,7 @@
from plyer import gps from plyer import gps
from kivy.app import App from kivy.app import App
from kivy.clock import Clock from kivy.clock import Clock
from kivy.properties import DictProperty, NumericProperty from kivy.properties import DictProperty, NumericProperty, StringProperty
from kivy.clock import mainthread from kivy.clock import mainthread
from kivy.utils import platform from kivy.utils import platform
from kivy_garden.mapview import MapView from kivy_garden.mapview import MapView
@ -12,6 +12,8 @@ from kivy.vector import Vector
from kivy.animation import Animation from kivy.animation import Animation
from math import atan2, sin, cos, degrees, floor from math import atan2, sin, cos, degrees, floor
from geopy.distance import geodesic
class MapScreen(Screen): class MapScreen(Screen):
pass pass
@ -28,6 +30,8 @@ class FlockompassApp(App):
needle_angle = NumericProperty(0) needle_angle = NumericProperty(0)
fbearing = NumericProperty(0) fbearing = NumericProperty(0)
dest_distance = StringProperty("")
def dump(self, dt): def dump(self, dt):
print(dt, self.gps_data, self.session_data) print(dt, self.gps_data, self.session_data)
@ -60,7 +64,8 @@ class FlockompassApp(App):
@mainthread @mainthread
def on_location(self, **kwargs): def on_location(self, **kwargs):
self.gps_data = kwargs self.gps_data = kwargs
self.dump(1)
if ('dest_lat' not in self.session_data if ('dest_lat' not in self.session_data
and and
'dest_lon' not in self.session_data): 'dest_lon' not in self.session_data):
@ -82,6 +87,11 @@ class FlockompassApp(App):
self.fbearing = self.needle_angle - degrees(self.fbearing) self.fbearing = self.needle_angle - degrees(self.fbearing)
self.fbearing = (self.fbearing + 360) % 360 self.fbearing = (self.fbearing + 360) % 360
self.dest_distance = "D: %0.1f km" % geodesic(
(self.gps_data['lat'], self.gps_data['lon']),
(self.session_data['dest_lat'], self.session_data['dest_lon'])).kilometers
print(self.dest_distance)
def center_map_on_gps(self): def center_map_on_gps(self):
self.ms.ids.mapview.center_on(self.gps_data['lat'], self.ms.ids.mapview.center_on(self.gps_data['lat'],
self.gps_data['lon']) self.gps_data['lon'])
@ -96,7 +106,7 @@ class FlockompassApp(App):
if self.cs.facade.field != (None, None, None): if self.cs.facade.field != (None, None, None):
x, y, z = self.cs.facade.field x, y, z = self.cs.facade.field
smoothingFactor = 0.9 smoothingFactor = 0.5
angle = atan2(y, x) angle = atan2(y, x)
self.last_angle = smoothingFactor * self.last_angle + (1 - smoothingFactor) * angle self.last_angle = smoothingFactor * self.last_angle + (1 - smoothingFactor) * angle