getLocation takes 0 positional arguments but 1 was given?
Hello everybody trying to create a button when pressed a label will display the current location. However i get a type error " getLocation takes 0 positional arguments but 1 was given
Here is the code
import location, ui def getLocation(): location.start_updates() loc = location.get_location() location.stop_updates() #label1.text += loc def getStreetAddress(loc): return location.reverse_geocode(loc) label1.text = loc main_view = ui.View(name = 'Location') main_view.bg_color = '#bfff8e' button1 = ui.Button(title = 'location') button1.frame = (0,30,75,75) button1.tint_color = 'black' button1.action = getLocation label1 = ui.Label(text = '') label1.number_of_lines = 0 label1.border_width = 1 label1.frame = (100,0,500,200) main_view.present() main_view.add_subview(button1) main_view.add_subview(label1)
Searched for helped but have not found any for that perticular issue
ui.actions take a parameter which is usually called
sender. In this case, Pythonista will set
button1, i.e. the ui element that the user selected.
import location import ui def getLocation(sender): location.start_updates() label1.text = str(location.get_location()) location.stop_updates() label1 = ui.Label(border_width=1, frame=(100, 0, 500, 200), number_of_lines=0) main_view = ui.View(name='Location', bg_color='#bfff8e') main_view.add_subview(label1) main_view.add_subview(ui.Button(title='location', frame=(0, 30, 75, 75), tint_color='black', action=getLocation)) main_view.present()
@ccc ah cool thx as always very helpful.
One quick question: tried your code and the return value in the label is "None"
Shouldn't there be gps cordinates when using the
Do you have
Settings / Privacy / Location Servicesturned on? Is Pythonista's access to those location services also turned on?
# loc_test.py import location location.start_updates() print(location.get_location()) location.stop_updates()
@ccc yes they are all turned on. Hmm could this maybe be cause of the hotels wifi restriction? Seems like I can't get a proper location for safari too.
Will try again when Im home. Thanks for the help anyway
Which is returning None? get_location, or reverse_geocode?
@JonB no it's the
getLocation()function that returns "none" not using reverse_geocode removed that part for now, thought that I could start with
getLocationand get something returned
@Bjucha If the four line
Nonethen please try rebooting your iOS device.
What iOS version? What Pythonista version?
@ccc tried rebooting still get the "None" message. I have 10.3.1 on my iPad and pythonista 3.1 with python 3.5