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.


    Reverse Geolocation works on console but not in code

    Pythonista
    4
    6
    3480
    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.
    • oldCovfefe
      oldCovfefe last edited by ccc

      Code snippet:

      import location
      
      location.start_updates()
      loc_dic = location.get_location()
      addr_dic = location.reverse_geocode(loc_dic)
      

      Get location works fine, converting it to a friendly street address does not. When I enter the same statement (the last line) in the console, it works just fine and creates a dictionary with all the interesting info. Any ideas what could be going on? Is it a timing issue, meaning I have to wait until it’s populated?

      Thanks

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

        @oldCovfefe I'be tried your little script without any error

        1 Reply Last reply Reply Quote 1
        • JonB
          JonB last edited by

          Iirc sometimes it might take a few tried to get a valid location. Maybe try repeating until location returns a non null result

          1 Reply Last reply Reply Quote 1
          • oldCovfefe
            oldCovfefe last edited by

            tried that, but it only resulted in a hung loop ... there is something else funky going on, because from the console it works just fine.

            mikael 1 Reply Last reply Reply Quote 0
            • mikael
              mikael @oldCovfefe last edited by

              @oldCovfefe, did you try waiting a bit with ui.delay?

              1 Reply Last reply Reply Quote 1
              • oldCovfefe
                oldCovfefe last edited by oldCovfefe

                I finally found the issue. The code works fine on the main level of the app, but has these issue when triggered from a event handler (a function call from an action attribute). The following directive solves the issue:

                import location
                
                @ui.in_background
                def button_tapped(sender):
                   location.start_updates()
                   loc_dic = location.get_location()
                   addr_dic = location.reverse_geocode(loc_dic) 
                   ...
                
                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors