UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Get GPS coordinates via terminal or python?

    Scheduled Pinned Locked Moved App Development
    5 Posts 4 Posters 1.0k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • J Offline
        Jarsa
        last edited by

        What is the (easiest) way to get current location or information about last known location using cli-command or python script? I am trying to write my first app for phones, so help is needed πŸ™‚

        1 Reply Last reply Reply Quote 1
        • poVoqP Offline
          poVoq
          last edited by

          https://github.com/ernesst/Utrack/

          This should give you the needed hints I think.

          Fairphone 5 (waiting for port)

          1 Reply Last reply Reply Quote 0
          • flohackF Offline
            flohack
            last edited by

            There is no store for the "last known location" - also location is an asynchronous thing, you have to request it, and then continue doing other stuff, and after some time (shorter or longer depending on GPS coverage) you will receive a callnack with the current location (if location is turned on, and your App is not blocked by the user).

            So its more a thing of responding to the actual location.

            That said, command line is not a good place to start an app with. You can create a simple QML App that requests location. Also remember you need to put location access into the appΒ΄s manifest so that the system knows your app is depending on location.

            My languages: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jarsa
              last edited by

              Thank you both! This was more like a pre-app planning and testing ideas thing πŸ™‚

              I didn't know if there is a whoami type of command to location. So I checked the Utrack and quickly writed my own whereami-script.

              Here is the code if someone needs it.

              #!/usr/bin/env python3
              # -*- coding: utf-8 -*-
              
              import subprocess
              
              
              def whereami():
                  print('Searching...')
                  latitude = ''
                  longitude = ''
                  for line in get_data():
                      if 'latitude' in line.decode("utf-8").lower():
                          latitude = line.decode("utf-8")
                      if 'longtide' in line.decode("utf-8").lower():
                          longitude = line.decode("utf-8") 
                      if latitude and longitude:
                          print('Location:\n {}\n {}'.format(latitude, longitude))
                          break
                          
              def get_data():
                  cmd = "sudo test_gps"
                  gps_data = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
                  
                  while True:
                      line = gps_data.stdout.readline().rstrip()
                      if not line:
                          break
                      yield line
                                     
              if __name__=='__main__':
                  whereami()
              
              H 1 Reply Last reply Reply Quote 0
              • H Offline
                htc_tattoo @Jarsa
                last edited by

                @Jarsa nice idea! I would like to use this idea as an onlinetracking system for myself. As i do outdoorsports, sending my last location to my own server is a good idea.
                In Android (9) it was very hard because of power limitations. As soon as the screen is off, everything goes to powersaving. And gps eats the battery as the cpu stays always on...
                This could be the limiting problem here too: the battery will be drained like hell...
                Is there a way to reduce power consumption?

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post