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.


    Location Module

    Pythonista
    2
    7
    3356
    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.
    • recon22
      recon22 last edited by recon22

      Hello,

      I have the following code:

      def currentlocation_tapped(sender):
             location.start_updates()
             currentlocation = location.get_location()
             CURRENTCOORDINATES = sender.superview['currentcoordinates']
             CURRENTCOORDINATES.text = "Current Coordinates : " + str(currentlocation)
             location.stop_updates()
      

      When I try to run this to update my textview text it returns none. I have to go manually to the settings to turn on location services for the app when testing and still I receive "None" as a returned string.

      Is there an error with how I am naming variables? Has anyone used this function successfully, I have seen others remarking that this function has not worked for them while the other ones in the module have.

      Thank you!

      cvp 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @recon22 last edited by cvp

        @recon22 if CURRENTCOORDINATES is an ui.TextView, you have to set

        CURRENTCOORDINATES.text = ...
        
        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @recon22 last edited by

          @recon22 Try this

          import ui
          import location
          
          def currentlocation_tapped(sender):
          	location.start_updates()
          	currentlocation = location.get_location()
          	CURRENTCOORDINATES = sender.superview['currentcoordinates']
          	CURRENTCOORDINATES.text = "Current Coordinates : " + str(currentlocation)
          	location.stop_updates()
          	
          v = ui.View()
          v.frame = (0,0,400,400)
          tv = ui.TextView(name='currentcoordinates')
          tv.frame = (0,100,400,300)
          v.add_subview(tv)
          b = ui.Button()
          b.frame = (0,0,400,100)
          b.title = 'tap'
          b.action = currentlocation_tapped
          v.add_subview(b)
          v.present('sheet')
          
          1 Reply Last reply Reply Quote 0
          • recon22
            recon22 last edited by

            Hi @cvp

            Thank you for the speedy reply. There was a typo in my original post. I did have the .text suffix.

            Everything prints out fine except the str(currentlocation).It just returns None.

            I checked by adding +str(location.is_authorized) and have received a string that says the module is authorized.

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

              @recon22 With my little script, I get

              Current Coordinates : {'latitude': xx.68955798919409, 'longitude': x.393751010242174, 'altitude': 101.77072143554688, 'timestamp': 1536907994.991019, 'horizontal_accuracy': 65.0, 'vertical_accuracy': 10.0, 'speed': -1.0, 'course': -1.0}
              
              1 Reply Last reply Reply Quote 0
              • recon22
                recon22 last edited by recon22

                Hello @cvp ,

                I tried the code out in Pythonista and I was able to run my app and get the coordinates successfully...

                However!

                When I placed it in the app template provided by @omz and tried the location module I was not able to use it. The error message I received was

                Traceback (most recent call last):
                  File "/var/mobile/Containers/Data/Application/11A60AF2-A1D5-4F30-981C-7A65792D1D3A/Library/Application Support/PythonistaScript/main.py", line 24, in currentlocation_tapped
                    gpslongitude = currentlocation.get("longitude")
                AttributeError: 'NoneType' object has no attribute 'get'
                
                

                Will the location module work once the app is published on the App Store? Will the user be able to allow the location in the settings at that point?

                Currently, when I load the app onto my iPhone for testing, when I go to my settings to set the privacy options to allow geo-location for my app it shows it as 'Never' then when I click that and go back I am allowed to choose 'Always', not sure why that is happening or if that is the cause of the issue...

                Not sure why the location module is working fine with the same code within Pythonista and behaves differently(throws errors) when loaded into xCode.

                --------SOLVED--------
                I needed to update the info.plist to include the various location usage keys and accompanying string.

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

                  @recon22 I can’t help you more because I don’t know the App Template, sorry.

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