Forum Archive

getLocation takes 0 positional arguments but 1 was given?

Bjucha

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)[0]
    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

ccc

Just change def getLocation(): to def getLocation(sender):

ui.actions take a parameter which is usually called sender. In this case, Pythonista will set sender to be 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()
Bjucha

@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 GetLocation() function?

ccc

Do you have Settings / Privacy / Location Services turned 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()
Bjucha

@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

JonB

Which is returning None? get_location, or reverse_geocode?

Bjucha

@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 getLocation and get something returned

ccc

@Bjucha If the four line test_loc.py above prints None then please try rebooting your iOS device.

What iOS version? What Pythonista version?

Bjucha

@ccc tried rebooting still get the "None" message. I have 10.3.1 on my iPad and pythonista 3.1 with python 3.5