define source in items own kv files. implement basic gps permissions
This commit is contained in:
parent
32d59cbd87
commit
586732dce1
6 changed files with 64 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
#:import MapView kivy_garden.mapview.MapView
|
||||
#:import GpsBlinker gpsblinker.GpsBlinker
|
||||
#:include gpsblinker.kv
|
||||
#:include treemarker.kv
|
||||
|
||||
<ForestMapView>:
|
||||
lat: 42.131331
|
||||
|
|
|
@ -41,7 +41,7 @@ class ForestMapView(MapView):
|
|||
# Create TreeMarker
|
||||
name = tree[0]
|
||||
lat, lon = tree[1], tree[2]
|
||||
treemarker = TreeMarker(lat=lat, lon=lon, source='assets/images/markers/tree.png')
|
||||
treemarker = TreeMarker(lat=lat, lon=lon)
|
||||
treemarker.tree_data = treemarker
|
||||
|
||||
# Add TreeMarker to the map
|
||||
|
|
58
gpshelper.py
58
gpshelper.py
|
@ -1,12 +1,66 @@
|
|||
from kivy.app import App
|
||||
from kivy.utils import platform
|
||||
from kivymd.uix.dialog import MDDialog
|
||||
|
||||
class GpsHelper():
|
||||
has_centered_map = False
|
||||
|
||||
def run(self):
|
||||
# Start blinking the GpsBlinker
|
||||
|
||||
# Get a reference to GpsBlinker, then call blink()
|
||||
#gps_blinker = App.get_running_app().root.ids.mapview.ids.blinker
|
||||
#gps_blinker = App.get_running_app().root.ids.forestmapview.ids.blinker
|
||||
#gps_blinker.blink()
|
||||
|
||||
# Request permission on Android
|
||||
# Request permissions on Android
|
||||
if platform == 'android':
|
||||
from android.permissions import Permission, request_permissions
|
||||
def callback(permission, results):
|
||||
if all([res for res in results]):
|
||||
print("Got all permissions")
|
||||
from plyer import gps
|
||||
gps.configure(on_location=self.update_blinker_position,
|
||||
on_status=self.on_auth_status)
|
||||
gps.start(minTime=1000, minDistance=0)
|
||||
else:
|
||||
print("Did not get all permissions")
|
||||
|
||||
request_permissions([Permission.ACCESS_COARSE_LOCATION,
|
||||
Permission.ACCESS_FINE_LOCATION], callback)
|
||||
|
||||
# Configure GPS
|
||||
if platform == 'ios':
|
||||
from plyer import gps
|
||||
gps.configure(on_location=self.update_blinker_position,
|
||||
on_status=self.on_auth_status)
|
||||
gps.start(minTime=1000, minDistance=0)
|
||||
|
||||
|
||||
def update_blinker_position(self, *args, **kwargs):
|
||||
my_lat = kwargs['lat']
|
||||
my_lon = kwargs['lon']
|
||||
print("GPS POSITION", my_lat, my_lon)
|
||||
# Update GpsBlinker position
|
||||
gps_blinker = App.get_running_app().root.ids.mapview.ids.blinker
|
||||
gps_blinker.lat = my_lat
|
||||
gps_blinker.lon = my_lon
|
||||
|
||||
# Center map on gps
|
||||
if not self.has_centered_map:
|
||||
map = App.get_running_app().root.ids.mapview
|
||||
map.center_on(my_lat, my_lon)
|
||||
self.has_centered_map = True
|
||||
|
||||
|
||||
def on_auth_status(self, general_status, status_message):
|
||||
if general_status == 'provider-enabled':
|
||||
pass
|
||||
else:
|
||||
self.open_gps_access_popup()
|
||||
|
||||
def open_gps_access_popup(self):
|
||||
dialog = MDDialog(title="GPS Error", text="You need to enable GPS access for the app to function properly")
|
||||
dialog.size_hint = [.8, .8]
|
||||
dialog.pos_hint = {'center_x': .5, 'center_y': .5}
|
||||
dialog.open()
|
||||
|
||||
|
|
2
main.kv
2
main.kv
|
@ -2,4 +2,4 @@
|
|||
|
||||
ForestMapView:
|
||||
orientation: 'vertical'
|
||||
id: mapview
|
||||
id: forestmapview
|
||||
|
|
Loading…
Reference in a new issue