show distance to destination, and icon
This commit is contained in:
parent
44777805b2
commit
3b62936b2a
@ -36,7 +36,7 @@ version = 0.1
|
||||
|
||||
# (list) Application requirements
|
||||
# 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
|
||||
# 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
|
||||
|
||||
# (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)
|
||||
orientation = portrait
|
||||
|
||||
@ -58,13 +58,18 @@
|
||||
important: True
|
||||
text: 'set destination'
|
||||
on_press: root.manager.current = 'map';
|
||||
|
||||
FloatLayout:
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .9, .9, .9
|
||||
Rectangle:
|
||||
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:
|
||||
source: 'needle.png'
|
||||
canvas.before:
|
||||
|
||||
14
main.py
14
main.py
@ -1,7 +1,7 @@
|
||||
from plyer import gps
|
||||
from kivy.app import App
|
||||
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.utils import platform
|
||||
from kivy_garden.mapview import MapView
|
||||
@ -12,6 +12,8 @@ from kivy.vector import Vector
|
||||
from kivy.animation import Animation
|
||||
from math import atan2, sin, cos, degrees, floor
|
||||
|
||||
from geopy.distance import geodesic
|
||||
|
||||
|
||||
class MapScreen(Screen):
|
||||
pass
|
||||
@ -28,6 +30,8 @@ class FlockompassApp(App):
|
||||
needle_angle = NumericProperty(0)
|
||||
fbearing = NumericProperty(0)
|
||||
|
||||
dest_distance = StringProperty("")
|
||||
|
||||
def dump(self, dt):
|
||||
print(dt, self.gps_data, self.session_data)
|
||||
|
||||
@ -60,6 +64,7 @@ class FlockompassApp(App):
|
||||
@mainthread
|
||||
def on_location(self, **kwargs):
|
||||
self.gps_data = kwargs
|
||||
self.dump(1)
|
||||
|
||||
if ('dest_lat' not in self.session_data
|
||||
and
|
||||
@ -82,6 +87,11 @@ class FlockompassApp(App):
|
||||
self.fbearing = self.needle_angle - degrees(self.fbearing)
|
||||
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):
|
||||
self.ms.ids.mapview.center_on(self.gps_data['lat'],
|
||||
self.gps_data['lon'])
|
||||
@ -96,7 +106,7 @@ class FlockompassApp(App):
|
||||
if self.cs.facade.field != (None, None, None):
|
||||
x, y, z = self.cs.facade.field
|
||||
|
||||
smoothingFactor = 0.9
|
||||
smoothingFactor = 0.5
|
||||
angle = atan2(y, x)
|
||||
self.last_angle = smoothingFactor * self.last_angle + (1 - smoothingFactor) * angle
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user