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
-
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!
-
@recon22 if CURRENTCOORDINATES is an ui.TextView, you have to set
CURRENTCOORDINATES.text = ...
-
@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')
-
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.
-
@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}
-
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. -
@recon22 I can’t help you more because I don’t know the App Template, sorry.