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.


    Problem with location

    Pythonista
    2
    4
    1054
    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.
    • tmessers
      tmessers last edited by

      Hello everybody,
      i have a problem using location.geocode.
      By using a ui, i want to get the geocode of an
      address.

      Although from my view the dict is created properly,
      the result, when operated by location.geocode is „None„.
      I cant find my fault.
      Does anybody else find it?

      Thanks

      import ui
      import location
      
      
      def button_tapped(sender):
      	if sender.title == "Execute":
      		adresse()
      		
      	elif sender.title == "Delete":
      		tf1.text = ""
      		tf2.text = ""
      		tf3.text = ""
      	
      	elif sender.title == "Map":
      		lon=float(tf1.text)
      		lat=float(tf2.text)
      		karte(lon,lat)
      
      mg=20
      w=200
      h=30
      mg1=((2*mg)+w)
      mg2=((3*mg)+(2*w))
      bw=200
      
      def make_textfield(text,frame):
          return ui.TextField(text=text, frame=frame, bordered =True, clear_button_mode='always')
      
      def make_button(title, frame):
          return ui.Button(title=title, frame=frame, bordered=True, border_width=2,   action=button_tapped)
          
      v=ui.View(name='Koordinaten',bg_color='grey',tint_color='black',border_width=1)
      tf1=make_textfield(text='Street',frame=(mg,((2*mg)+h),w,h))#tf1
      v.add_subview(tf1)
      tf2=make_textfield(text='City',frame=(mg1, ((2*mg)+h),w,h)) #tf2
      v.add_subview(tf2)
      tf3=make_textfield(text='Country',frame=(mg2, ((2*mg)+h),w,h)) #tf2
      v.add_subview(tf3)
      tf4=make_textfield(text='tf4',frame=(mg1, ((3*mg)+(2*h)),w,h)) #tf2
      v.add_subview(tf4)
      tf5=make_textfield(text='tf5',frame=(mg2, ((3*mg)+(2*h)),w,h)) #tf2
      v.add_subview(tf5)
      
      v.add_subview(make_button(title='Execute',frame=(mg,((8*mg)+(7*h)),w,h)))
      v.add_subview(make_button(title='Delete',frame=(mg1,((8*mg)+(7*h)),w,h)))
      v.add_subview(make_button(title='Map',frame=(mg2,((8*mg)+(7*h)),w,h)))
      v.present()
      
      def adresse():
      	#print("addresse ok")
      	road=tf1.text
      	#print(strasse)
      	town=tf2.text
      	#print(stadt)
      	land=tf3.text
      	#print(land)
      	addresse= {'Street': road, 'City': town, 'Country': land}
      	print ("1: %s" %addresse)
      	results = location.geocode(addresse)
      	print ("1: %s" %results)
      	if results != None:
      		zwischen1=round(results[0]['latitude'],6)
      		tf4.text=str(zwischen1)
      		zwischen2=round(results[0]['longitude'],6)
      		tf5.text=str(zwischen2)
      
      
      cvp 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @tmessers last edited by

        @tmessers use

        @ui.in_background
        def adresse(): 
        
        1 Reply Last reply Reply Quote 1
        • cvp
          cvp @tmessers last edited by

          @tmessers and for a nicer TextField initialization, use placeholder

          def make_textfield(text,frame):
              return ui.TextField(placeholder=text, frame=frame, bordered =True, clear_button_mode='always') 
          
          1 Reply Last reply Reply Quote 1
          • tmessers
            tmessers last edited by

            @cvp
            Thank you, both hints worked well.

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