dynamicaly set mapview lat,lon
This commit is contained in:
parent
1d04daef0f
commit
2b317fefa3
@ -20,10 +20,8 @@
|
|||||||
|
|
||||||
MapView:
|
MapView:
|
||||||
id: mapview
|
id: mapview
|
||||||
lat: 28.89335172
|
|
||||||
lon: 76.59449171
|
|
||||||
zoom: 15
|
zoom: 15
|
||||||
|
|
||||||
on_map_relocated: centermark.lat = mapview.lat; centermark.lon = mapview.lon
|
on_map_relocated: centermark.lat = mapview.lat; centermark.lon = mapview.lon
|
||||||
|
|
||||||
MapMarker:
|
MapMarker:
|
||||||
@ -31,9 +29,6 @@
|
|||||||
id: centermark
|
id: centermark
|
||||||
anchor_x: 0.2
|
anchor_x: 0.2
|
||||||
anchor_y: 0.3
|
anchor_y: 0.3
|
||||||
lat: 28.89335172
|
|
||||||
lon: 76.59449171
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<CompassScreen>:
|
<CompassScreen>:
|
||||||
|
|||||||
51
main.py
51
main.py
@ -12,15 +12,16 @@ from kivy_garden.mapview import MapView
|
|||||||
from kivy.vector import Vector
|
from kivy.vector import Vector
|
||||||
from kivy.animation import Animation
|
from kivy.animation import Animation
|
||||||
from math import floor
|
from math import floor
|
||||||
|
import random
|
||||||
|
|
||||||
|
#from LatLon23 import LatLon, Latitude, Longitude
|
||||||
|
|
||||||
|
|
||||||
class MapScreen(Screen):
|
class MapScreen(Screen):
|
||||||
hue = NumericProperty(0)
|
mapview = MapView()
|
||||||
mapview = MapView(zoom=11, lat=50.6394, lon=3.057)
|
|
||||||
|
|
||||||
|
|
||||||
class CompassScreen(Screen):
|
class CompassScreen(Screen):
|
||||||
hue = NumericProperty(0)
|
|
||||||
x_calib = NumericProperty(0)
|
x_calib = NumericProperty(0)
|
||||||
y_calib = NumericProperty(0)
|
y_calib = NumericProperty(0)
|
||||||
z_calib = NumericProperty(0)
|
z_calib = NumericProperty(0)
|
||||||
@ -31,7 +32,7 @@ class CompassScreen(Screen):
|
|||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
self.facade.enable()
|
self.facade.enable()
|
||||||
Clock.schedule_interval(self.get_field, 1 / 20.)
|
Clock.schedule_interval(self.get_field, 1 / 5.)
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
self.facade.disable()
|
self.facade.disable()
|
||||||
@ -76,10 +77,22 @@ class CompassScreen(Screen):
|
|||||||
@mainthread
|
@mainthread
|
||||||
def on_location(self, **kwargs):
|
def on_location(self, **kwargs):
|
||||||
print('aguas on location')
|
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([
|
self.gps_location = '\n'.join([
|
||||||
'{}={}'.format(k, v) for k, v in kwargs.items()])
|
'{}={}'.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
|
@mainthread
|
||||||
def on_status(self, stype, status):
|
def on_status(self, stype, status):
|
||||||
print('aguas on status')
|
print('aguas on status')
|
||||||
@ -90,6 +103,22 @@ class CompassScreen(Screen):
|
|||||||
|
|
||||||
class FlockompassApp(App):
|
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):
|
def request_android_permissions(self):
|
||||||
from android.permissions import request_permissions, Permission
|
from android.permissions import request_permissions, Permission
|
||||||
|
|
||||||
@ -106,9 +135,13 @@ class FlockompassApp(App):
|
|||||||
def build(self):
|
def build(self):
|
||||||
|
|
||||||
root = ScreenManager(transition=RiseInTransition())
|
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 = CompassScreen(name='compass')
|
||||||
cs._anim = None
|
cs._anim = None
|
||||||
|
cs.p = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
gps.configure(on_location=cs.on_location,
|
gps.configure(on_location=cs.on_location,
|
||||||
@ -122,8 +155,12 @@ class FlockompassApp(App):
|
|||||||
print("gps.py: Android detected. Requesting permissions")
|
print("gps.py: Android detected. Requesting permissions")
|
||||||
self.request_android_permissions()
|
self.request_android_permissions()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
root.add_widget(cs)
|
root.add_widget(cs)
|
||||||
|
|
||||||
|
Clock.schedule_interval(self.move_around, 2.0)
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user