Reverse Geolocation works on console but not in code
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?
@oldCovfefe I'be tried your little script without any error
Iirc sometimes it might take a few tried to get a valid location. Maybe try repeating until location returns a non null result
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.
@oldCovfefe, did you try waiting a bit with ui.delay?
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) ...