Qpython Plyer GPS - gps.start()方法调用崩溃

时间:2015-07-13 18:20:17

标签: android python gps kivy qpython

我的目标是使用python模块 Plyer 版本1.2.4 知道我的Nexus 5( Andrid 5.1.1 )的地理坐标EM>)。

所以我在我的智能手机上安装了解释器 QPython2.7 Version 1.0.6 ),并编写了以下代码,其灵感来自于Plyer文档中的示例{{3 }。 Qpyton2.7安装包括我在代码中使用的 Kivy 模块(版本1.8.0 )。

我希望该计划能做什么:

当我按下按钮时,程序会在我再次按下该按钮时启动位置更新,程序将停止更新。 当程序更新位置时,它会调用loc()方法来更新当前位置的按钮文本值。

该计划真正做了什么:

它在gps.start()调用时崩溃。

备注:

程序在gps.configure()之前的调用中没有崩溃。 Plyer模块的方法vibrator.vibrate()工作正常!

报告错误:

...

文件" jnius_export_class.pxi",第562行,在jnius.jnius.JavaMethod中。调用(jnius / jnius.c:17724)    文件" jnius_export_class.pxi",第656行,在jnius.jnius.JavaMethod.call_method(jnius / jnius.c:18722)    文件" jnius_utils.pxi",第43行,在jnius.jnius.check_exception(jnius / jnius.c:3175) jnius.jnius.JavaException:发生JVM异常

代码:

#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 个答案:

答案 0 :(得分:0)

代码无法运行,因为方法调用bes gps plyer作为参数传递on_location =其功能示例:

NSToolbarItem