Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android kivy plyer GPS-将数据转换为字符串_Android_Python_Gps_Kivy - Fatal编程技术网

Android kivy plyer GPS-将数据转换为字符串

Android kivy plyer GPS-将数据转换为字符串,android,python,gps,kivy,Android,Python,Gps,Kivy,我很难将变量“gps_location”中包含的数据转换为字符串,这将允许我处理数据 我曾尝试使用strvariable转换为字符串,但这不起作用,我还在变量末尾添加了.show和.text from kivy.lang import Builder from plyer import gps from kivy.app import App from kivy.properties import StringProperty from kivy.clock import Clock kv =

我很难将变量“gps_location”中包含的数据转换为字符串,这将允许我处理数据

我曾尝试使用strvariable转换为字符串,但这不起作用,我还在变量末尾添加了.show和.text

from kivy.lang import Builder
from plyer import gps
from kivy.app import App
from kivy.properties import StringProperty
from kivy.clock import Clock

kv = '''
BoxLayout:
    orientation: 'vertical'

    Label:
        text: app.gps_info

    Label:
        text: app.gps_location

    Label:
        text: app.gps_status

    BoxLayout:
        size_hint_y: None
        height: '48dp'
        padding: '4dp'

        ToggleButton:
            text: 'Start' if self.state == 'normal' else 'Stop'
            on_state: app.gps.start() if self.state == 'down' else app.gps.stop()
'''

def mainthread(func):
    # This method is now part of Kivy 1.8.0. When it's released, remove it.
    def delayed_func(*args, **kwargs):
        def callback_func(dt):
            func(*args, **kwargs)
        Clock.schedule_once(callback_func, 0)
    return delayed_func


class GpsTest(App):

    gps_location = StringProperty()
    gps_status = StringProperty('Click Start to get GPS location updates')
    gps_info = str(gps_location)


    def build(self):
        self.gps = gps
        try:
            self.gps.configure(on_location=self.on_location,
                on_status=self.on_status)
        except NotImplementedError:
            import traceback; traceback.print_exc()
            self.gps_status = 'GPS is not implemented for your platform'

        return Builder.load_string(kv)

    @mainthread
    def on_location(self, **kwargs):
        self.gps_location = '\n'.join([
            '{}={}'.format(k, v) for k, v in kwargs.items()])

    @mainthread
    def on_status(self, stype, status):
       self.gps_status = 'type={}\n{}'.format(stype, status)

if __name__ == '__main__':
    GpsTest().run()

感谢您的时间

Plyer GPS示例有一些代码可以帮助您