omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Extract only latitude and longitude from location

    Pythonista
    2
    3
    1448
    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.
    • secmast
      secmast last edited by

      With this simple script I can get the complete location information from the unit GPS.

      import location, time

      a=""
      label1 = ""

      def getlocation(sender):
      location.start_updates()
      time.sleep(1)
      label1 = str(location.get_location())
      location.stop_updates()

      getlocation(a)
      print(a)

      And the result is the following
      {'latitude': 49.305450439453125, 'longitude': 2.5930605239319453, 'altitude': 28.290002822875977, 'timestamp': 1542108670.452639, 'horizontal_accuracy': 140.45985579622024, 'vertical_accuracy': 10.941082954406738, 'speed': -1.0, 'course': -1.0}

      But, and I’m sure this is simple but my knowledge of python and programming in general is really poor.
      How can I get only latitude and longitude information out of a ?
      More generally how can I convert something that seems to be a mix of string and number. As the A variable have quotes and special character like “:”.

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @secmast last edited by cvp

        @secmast try this

        import location, time
        
        a=""
        label1 = ""
        
        def getlocation():
        	location.start_updates()
        	time.sleep(1)
        	label1 = location.get_location()	# returns a dictionnary
        	location.stop_updates()
        	return label1
        
        a = getlocation()
        print(a)
        # get two elements from dictinnary
        lat = a['latitude']
        lon = a['longitude']
        print(lat,lon)```
        1 Reply Last reply Reply Quote 0
        • secmast
          secmast last edited by

          Thanks...
          In fact writing the post I discover that I just need to understand a bit better the Variable type under Python.
          In this case this is a dictionary.
          Now I need to read a bit about dict type...
          But thanks...

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors