Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPS double output on output return value #302

Closed
kujuablockchain opened this issue Mar 12, 2017 · 2 comments
Closed

GPS double output on output return value #302

kujuablockchain opened this issue Mar 12, 2017 · 2 comments

Comments

@kujuablockchain
Copy link

kujuablockchain commented Mar 12, 2017

Hi,

I've been on this for days. Basically i am trying to return the latitude and longitude values. The output works, the problem is that is outputs double even if i put a sleep time limit of 3 or 5 seconds. Is there a way to have the return value of print_locations only return one set of latitude and longitude? I am obviously doing something wrong.

code:

from kivy.lang import Builder
from plyer import gps
from kivy.app import App
from kivy.properties import StringProperty
from kivy.clock import Clock, mainthread
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
import time

def gpsstart(self):
    self.gps = gps
    self.gps.start()
    time.sleep(5)
    self.gps.stop()

class MyScreenManager(ScreenManager):
    pass

class GpsTestScreen(Screen):
    pass

class GpsTestBoxLayout(BoxLayout):
    gps_location = StringProperty()
    def __init__(self, **kwargs):
        super(GpsTestBoxLayout, self).__init__(**kwargs)
        #self.cols = 1
        self.spacing=40
        self.padding=40

        self.add_widget(Button(text='Update and check logs', font_size=40, size_hint_y=None, height=80, on_press=gpsstart))

        self.gps = gps

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

        def print_locations(**kwargs):
            location = '{lat}, {lon}'.format(**kwargs)
            #location = location.split(":")[-1]
            print(location)
            return location

        self.test = TextInput(text='aim is to print the latest location is here\nbut "print_locations" outputs double', multiline=True, size_hint_y=None, height=160, padding=30)
        self.add_widget(self.test)

        try:
            self.gps.configure(on_location=print_locations)

        except NotImplementedError:
            import traceback
            traceback.print_exc()
            self.gps_status = 'GPS is not implemented for your platform'

kv = Builder.load_string('''
#:import NoTransition kivy.uix.screenmanager.NoTransition
#:import sys sys
MyScreenManager:
    transition: NoTransition()

    GpsTestScreen:
        ActionBar:
            pos_hint: {'top':1}
            ActionView:
                ActionPrevious:
                    with_previous: False

<GpsTestScreen>:
    name: 'gps'
    BoxLayout:
        GpsTestBoxLayout
            orientation: 'vertical'
            padding: [50,10,50,10]
            spacing: 10
            size_hint_y: 0.8
            Label:
                text: "[color=000000]test[/color]"
                markup: True
''')

class ScreenManagerApp(App):
    def build(self):
        return kv

ScreenManagerApp().run()

Logs showing double output for every press of a button:
I/python (22734): [INFO ] [Android ] discard joystick <0> cause no button
I/python (22734): [INFO ] [Android ] create joystick <1>
I/python (22734): [INFO ] [Android ] create joystick <2>
I/python (22734): [INFO ] [Android ] create joystick <3>
I/python (22734): [INFO ] [Android ] create joystick <4>
I/python (22734): [INFO ] [Android ] create joystick <5>
I/python (22734): [INFO ] [Android ] create joystick <6>
I/python (22734): [INFO ] [Android ] create joystick <7>
I/python (22734): [INFO ] [Android ] create joystick <8>
I/python (22734): [INFO ] [Android ] create joystick <9>
I/python (22734): [INFO ] [Android ] create joystick <10>
I/python (22734): [INFO ] [Android ] create joystick <11>
I/python (22734): [INFO ] [Android ] create joystick <12>
I/python (22734): [INFO ] [Android ] create joystick <13>
I/python (22734): [INFO ] [Android ] create joystick <14>
I/python (22734): [INFO ] [Android ] create joystick <15>
I/python (22734): [INFO ] [Android ] create joystick <16>
I/python (22734): -26.0717071, 27.9787612
I/python (22734): -26.0717071, 27.9787612
I/python (22734): -26.0716552, 27.9788069
I/python (22734): -26.0716552, 27.9788069


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@apariciojuan
Copy link

do not use time.sleep()
de interval of report is in minTime

gps.start(minTime, minDistance)

you can write gps.start(10000, 10)
where =
min_time, # minTime, in milliseconds
min_distance, # minDistance, in meters

now yours report lat and long every 10 seconds, you can do 1 report and then gps.stop()

sorry for my english

@kujuablockchain
Copy link
Author

Hi @apariciojuan you are right, that really helped thank you very much. Your english is good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants