old_contents: 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
  
  kv = '''
  BoxLayout:
      orientation: 'vertical'
  
      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(1000, 0) if self.state == 'down' else \
                  app.gps.stop()
  '''
  
  
  class GpsTest(App):
  
      gps_location = StringProperty()
      gps_status = StringProperty('Click Start to get GPS location updates')
  
      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()
  
new_contents: 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
  
  kv = '''
  BoxLayout:
      orientation: 'vertical'
  
      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.start(1000, 0) if self.state == 'down' else \
                  app.stop()
  '''
  
  
  class GpsTest(App):
  
      gps_location = StringProperty()
      gps_status = StringProperty('Click Start to get GPS location updates')
  
      def build(self):
          try:
              gps.configure(on_location=self.on_location,
                            on_status=self.on_status)
          except NotImplementedError:
              import traceback
              traceback.print_exc()
              gps_status = 'GPS is not implemented for your platform'
  
          return Builder.load_string(kv)
  
      def start(self, minTime, minDistance):
          gps.start(minTime, minDistance)
  
      def stop(self):
          gps.stop()
  
      @mainthread
      def on_location(self, **kwargs):
          gps_location = '\n'.join([
              '{}={}'.format(k, v) for k, v in kwargs.items()])
  
      @mainthread
      def on_status(self, stype, status):
          gps_status = 'type={}\n{}'.format(stype, status)
  
      def on_pause(self):
          gps.stop()
          return True
  
      def on_resume(self):
          gps.start(1000, 0)
          pass
  
  if __name__ == '__main__':
      GpsTest().run()
  
subject: improve example