python - 我想在我的 Kivy / Python 应用程序中实现 GPS,但我不知道该怎么做
问题描述
我在 Kivy / Python 中有一个应用程序,现在我需要实现一个函数,该函数捕获手机的最后纬度和经度,并将它们提供给 MainApp 函数中的另一个函数,因为我需要以变量形式执行此信息一些计算。
主文件
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?
解决方案
推荐阅读
- python - 从python中的csv中删除多次出现
- python - 输入操作数 1 在其核心维度 0 中存在不匹配,具有 gufunc 签名 (n?,k),(k,m?)->(n?,m?)(大小 133896 与 133809 不同)
- java - 我需要帮助将所有对最短路径算法实现到给定的代码中
- mysql - 关于将用户名和域名与电子邮件地址分开的问题
- java - 在电子邮件应用 Java 中找不到主类
- node.js - 通过 Codepipleline 在 Docker 上分发 Beanstalk 不完整
- sql - 在指定时间之前的 COUNT 次,自加入?
- c++ - 在没有 SA_RESTART 的情况下使用 sigaction 并防止无限循环
- css - 在 React 应用程序中使用 Scss 的随机字符串类名是什么意思?
- git - 重命名名称中带有破折号的文件夹