dynamicaly set mapview lat,lon

This commit is contained in:
rgarcia-herrera 2020-08-04 17:20:08 -05:00
parent 1d04daef0f
commit 2b317fefa3
2 changed files with 45 additions and 13 deletions

View File

@ -20,10 +20,8 @@
MapView:
id: mapview
lat: 28.89335172
lon: 76.59449171
zoom: 15
on_map_relocated: centermark.lat = mapview.lat; centermark.lon = mapview.lon
MapMarker:
@ -31,9 +29,6 @@
id: centermark
anchor_x: 0.2
anchor_y: 0.3
lat: 28.89335172
lon: 76.59449171
<CompassScreen>:

51
main.py
View File

@ -12,15 +12,16 @@ from kivy_garden.mapview import MapView
from kivy.vector import Vector
from kivy.animation import Animation
from math import floor
import random
#from LatLon23 import LatLon, Latitude, Longitude
class MapScreen(Screen):
hue = NumericProperty(0)
mapview = MapView(zoom=11, lat=50.6394, lon=3.057)
mapview = MapView()
class CompassScreen(Screen):
hue = NumericProperty(0)
x_calib = NumericProperty(0)
y_calib = NumericProperty(0)
z_calib = NumericProperty(0)
@ -31,7 +32,7 @@ class CompassScreen(Screen):
def enable(self):
self.facade.enable()
Clock.schedule_interval(self.get_field, 1 / 20.)
Clock.schedule_interval(self.get_field, 1 / 5.)
def disable(self):
self.facade.disable()
@ -76,10 +77,22 @@ class CompassScreen(Screen):
@mainthread
def on_location(self, **kwargs):
print('aguas on location')
print(kwargs)
# print(kwargs)
# p = LatLon(Latitude(kwargs['lat']),
# Longitude(kwargs['lon']))
# destination_point = LatLon(Latitude(28.89335172),
# Longitude(76.59449171))
self.gps_location = '\n'.join([
'{}={}'.format(k, v) for k, v in kwargs.items()])
# self.gps_location += str(p.heading_initial(destination_point))
# bearing = atan2(sin(long2-long1)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(long2-long1))
# bearing = degrees(bearing)
# bearing = (bearing + 360) % 360
# https://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points#4913653
@mainthread
def on_status(self, stype, status):
print('aguas on status')
@ -90,6 +103,22 @@ class CompassScreen(Screen):
class FlockompassApp(App):
lat = 19.3419
lon = -99.1499
def move_around(self, t):
self.lat += random.uniform(-0.01,0.01)
self.lon += random.uniform(-0.01,0.01)
self.ms.ids.mapview.center_on(self.lat, self.lon)
# where the marker's at
print(
self.ms.ids.centermark.lat,
self.ms.ids.centermark.lon
)
def request_android_permissions(self):
from android.permissions import request_permissions, Permission
@ -106,9 +135,13 @@ class FlockompassApp(App):
def build(self):
root = ScreenManager(transition=RiseInTransition())
root.add_widget(MapScreen(name='map'))
self.ms = MapScreen(name='map')
root.add_widget(self.ms)
cs = CompassScreen(name='compass')
cs._anim = None
cs.p = None
try:
gps.configure(on_location=cs.on_location,
@ -122,8 +155,12 @@ class FlockompassApp(App):
print("gps.py: Android detected. Requesting permissions")
self.request_android_permissions()
root.add_widget(cs)
Clock.schedule_interval(self.move_around, 2.0)
return root