我想在我的Kivy/Python应用程序中实现GPS,但我不知道如何实现

2024-03-29 11:41:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Kivy/Python应用程序,现在我需要实现一个函数,该函数捕获手机的最后一个纬度和经度,并为MainApp函数中的另一个函数提供这些纬度和经度,因为我需要以变量形式提供这些信息以进行一些计算

main.py

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.properties import ObjectProperty, ListProperty
from kivy.uix.image import Image

#-----------------------------------------------------------------------------------------------------------------------

Window.clearcolor = [1, 1, 0.9, 0.9]

class MainApp(App):
    texture = ObjectProperty()

#-----------------------------------------------------------------------------------------------------------------------

# >>>>>>>>> Here is the function that takes the latitude and longitude data from the GPS <<<<<<<<<<<<<<
    def gps

# >>>>>>>>> And I need her to give me this data in 'lat'e' lon 'variables here inside a new function called calcu, so that I can do the calculations I want
    def calcu

#-----------------------------------------------------------------------------------------------------------------------

    def build(self):
        self.title = 'MyApp'
        self.texture = Image(source = 'bgg.jpg').texture

    def calcular(self, *args):

        s_x = self.root.ids.x.text
        s_y = self.root.ids.y.text
        s_z = self.root.ids.z.text
        s_rpa = self.root.ids.rpa.text
        s_rt = self.root.ids.rt.text
        s_rpi = self.root.ids.rpi.text
        s_t = self.root.ids.t.text
        s_ii = self.root.ids.ii.text
        s_ie = self.root.ids.ie.text
        s_ac = self.root.ids.ac.text


#-----------------------------------------------------------------------------------------------------------------------

        # Condicionais e variáveis:

        if (s_x == ''):
            s_x = 6
        if (s_y == ''):
            s_y = 6
        if (s_z == ''):
            s_z = 3
        if (s_ie == ''):
            s_ie = 20000
        if (s_ii == ''):
            s_ii = 300
        if (s_t == ''):
            s_t = 0.88
        if (s_rpi == ''):
            s_rpi = 0.3
        if (s_rt == ''):
            s_rt = 0.7
        if (s_rpa == ''):
            s_rpa = 0.5
        if (s_ac == ''):
            s_ac = 90

        x = float(s_x)
        y = float(s_y)
        z = float(s_z)
        rpi = float(s_rpi)
        rt = float(s_rt)
        rpa = float(s_rpa)
        t = float(s_t)
        ac = float(s_ac)
        ii = float(s_ii)
        ie = float(s_ie)

#-----------------------------------------------------------------------------------------------------------------------

        # Equacões:

        apa = 2*((x*z)+(y*z))
        api = x * y
        at = x * y
        a = apa + api + at
        r = ((rpa * apa) + (rpi * api) + (rt * at)) / a
        fld = (ii/ie)*100
        w = (fld*a*(1-(r ** 2))) / (t*ac)
        w = round(w, 3)
        w = str(w)
        w = w.replace(".", ",")
        w = w +" m²"

#-----------------------------------------------------------------------------------------------------------------------

        # Botão calcular:

        if (( t<=0 or t>1 ) or ( rpa<=0 or rpa>=1 ) or ( rpi<=0 or rpi >=1 ) or ( rt<=0 or rt>=1 ) or (ac<=0 or ac>180)):
            the_popup = Popup(title='Erro', content=Label(id='_result', text='Valor fornecido invalido.'),size_hint=(.5, .2), separator_color=[1, 1, 0.6, 0.8])
            the_popup.open()
        else:
            self.root.ids.resultado.text = w
            self.root.ids.resultado.opacity = 1

#-----------------------------------------------------------------------------------------------------------------------

def exit(self):
        App.get_running_app().stop()

aplicativo = MainApp()
aplicativo.run()

考虑到未来的问题,我应该在buildozer.spec中修改什么配置,以便允许应用程序使用手机的gps


Tags: ortextfromselfidsifrootfloat