Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Untitled_215.py
# coding: utf-8
from objc_util import *
import ui
def printMethods(whichObject):
#print (dir(whichObject))
for method in dir(whichObject):
print (method)
#- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading;
def locationManager_didUpdateHeading_(self, _cmd, manager, newHeading):
headingObj = ObjCInstance(newHeading)
if v.on_screen:
def delayed_fcn():
v['m_Heading_value'].text = str(headingObj)
ui.delay(delayed_fcn,0.001)
#print ("Magnetic:", headingObj.magneticHeading())
#print ("True:",headingObj.trueHeading())
#print ("ACCURACY:",headingObj.headingAccuracy())
else:
ObjCInstance(manager).stopUpdatingHeading()
print('manager updated heading when view was not onscreen')
return
def locationManager_didUpdateLocations_(_self,_cmd,manager,locations):
locations=ObjCInstance(locations)
if v.on_screen:
def delayed_fcn():
v['m_loc_value'].text = '{}'.format(locations[0])
ui.delay(delayed_fcn,0.001)
else:
ObjCInstance(manager).stopUpdatingLocation()
print('manager updated loc when view was not onscreen')
return
def locationManager_didFailWithError_(_self,_cmd,manager,error):
error=ObjCInstance(error)
print (error)
methods = [locationManager_didUpdateHeading_,locationManager_didUpdateLocations_,locationManager_didFailWithError_]
protocols = ['CLLocationManagerDelegate']
MyLocationManagerDelegate = create_objc_class('MyLocationManagerDelegate', methods=methods, protocols=protocols)
class LocView(ui.View):
def __init__(self, *args,**kwargs):
ui.View.__init__(self,*args,**kwargs)
tv=ui.TextView(frame=(0,0,self.width,100),name='m_Heading_value')
tv.text='headings'
self.add_subview(tv)
tv.flex='w'
tv=ui.TextView(frame=(0,100,self.width,100),name='m_loc_value')
tv.text='locations'
tv.flex='w'
self.add_subview(tv)
self.setup_loc()
def will_close(self):
# we need to stop updates, delete locationmanager
on_main_thread(self.myloc.stopUpdatingHeading)()
on_main_thread(self.myloc.stopUpdatingLocation)()
print('**updates stopped**')
#mself.cleanup()
def cleanup(self):
#remove references to allow objects to be gc'd
del self.myloc
del self.delegate
def setup_loc(self):
CLLocationManager = ObjCClass ('CLLocationManager')
#myloc = CLLocationManager.alloc().init().autorelease()
myloc = CLLocationManager.sharedManager() # prevent many copies from getting instantiated
#print (printMethods(myloc))
delegate = MyLocationManagerDelegate.alloc().init()
myloc.setDelegate_(delegate)
locationAvailable = CLLocationManager.headingAvailable()
print ("HEADING AVAILABLE")
print (locationAvailable)
print ("CURRENT HEADING ORIENTATION")
print (myloc.headingOrientation())
print ("NEW HEADING ORIENTATION")
myloc.headingOrientation = 3
print (myloc.headingOrientation())
myloc.headingFilter = 3
myloc.distanceFilter = -1
myloc.desiredAccuracy=myloc.bestAccuracy()
print ("NEW THRESHOLD")
print (myloc.headingFilter())
self.myloc=myloc
self.delegate=delegate
@on_main_thread
def start_updates(self):
print ("START MONITORING ")
self.myloc.startUpdatingLocation()
self.myloc.startUpdatingHeading()
if __name__ == '__main__':
v=LocView(frame=(0,0,500,200))
v.present('sheet')
v.start_updates()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.