0

My goal is to know the geographic coordinates of my Nexus 5 (Andrid 5.1.1) using the python module Plyer(Version 1.2.4).

So I installed the interpreter QPython2.7(Version 1.0.6) on my smartphone and I wrote the following code inspired by the example on Plyer documentation https://plyer.readthedocs.org/en/latest/#plyer.facades.GPS . Qpyton2.7 installation include Kivy module(Version 1.8.0) that I used in my code.

What I expect the program do:

When I press the button the program'll start the location updates when I press it again the program'll stop the updates. When the program updates the location it'll call loc() method to update the button text value with the current location.

What the program really do:

It crashes on gps.start() call.

Notes:

The program doesn't crash on gps.configure() previous call. The method vibrator.vibrate() of Plyer module works fine!

Error reported:

...

File "jnius_export_class.pxi", line 562, in jnius.jnius.JavaMethod.call (jnius/jnius.c:17724) File "jnius_export_class.pxi", line 656, in jnius.jnius.JavaMethod.call_method (jnius/jnius.c:18722) File "jnius_utils.pxi", line 43, in jnius.jnius.check_exception (jnius/jnius.c:3175) jnius.jnius.JavaException: JVM exception occured

THE CODE:

#qpy:kivy

from plyer import vibrator
from plyer import gps
from kivy.app import App
from kivy.uix.button import Button


class TestApp(App):

    def build(self):
        self.locbutton = Button(text='START', on_press=self.start_stop)
        return self.locbutton

    def on_start(self):
        gps.configure(on_location=self.loc)

    def loc(self, **kwargs):
        self.locbutton.text = 'lat:{lat},lon:{lon}'.format(**kwargs)

    def start_stop(self, instance):
        if self.locbutton.text == 'START':
            #self.locbutton.text = 'STOP'
            gps.start()
        else:
            gps.stop()
            self.locbutton.text = 'START'
        vibrator.vibrate(0.01)

TestApp().run()

1 Answers1

0

The code does not run because of the method call bes gps plyer passing as parameters on_location = its function example:

from plyer import gps
from kivy.app import App
from import kivy.uix.button Button

class mi_app(App):
    def buscar_coord (self, **kwargs):
        info = Kwargs.items()
        ## Decodificas the json
        print str(info)
    def gps_activar(self, ins):
        self.buscar_coord()
    def build(self):
        gps.configure (on_location = self.buscar_coord)
        ## we call start method
        gps.start ()
        return Button(text = "TEST_GPS" on_release = self.gps_activar)

mi_app().run()
jeyfrin
  • 1
  • 1
  • 1
    jeyfrin, Thanks for your answer, but please be sure to always use the code formatting blocks to make your code readable to other users. – Matt C Apr 20 '16 at 18:40