Web1.GotText sometimes responseContent is empty

79 views
Skip to first unread message

Marco Perrone

unread,
Nov 22, 2019, 6:01:44 AM11/22/19
to mitappinv...@googlegroups.com
Hi everybody,
I am triyng to make a simple geocoding app. I use the https://nominatim.openstreetmap.org/ website for this purpose.
As You can see in the attached file I do a web request  for example:
and in the GotText i wait the response. 
My problem is that sometimes the responseContent is empty, but with the same url in the browser i have a correct answer.
Could be that GotText is fired before the responseContent is loaded with the data?
Best Regards
Thank You
Marco
map.png

TimAI2

unread,
Nov 22, 2019, 6:18:54 AM11/22/19
to MIT App Inventor Forum
Network/Data/Internet connection not always there? (you can test for this...See here - or there is an extension)

Perhaps setup to display the response Code when you do not get response Content to see what is happening?

Marco Perrone

unread,
Nov 22, 2019, 6:50:51 AM11/22/19
to MIT App Inventor Forum
Ok TimAI2 I will check
Thank You 
Best Regards
Marco

SteveJG

unread,
Nov 22, 2019, 8:25:41 AM11/22/19
to MIT App Inventor Forum
Use the  call Web1.UriEncode  text                 block ahead of your TextBox1.Text block  (or UriEncode everything in the  join .

Why?  What you type in the TextBox may contain characters outside the ASCII set.  The  UriEncode block converts what is typed into a valid ASCII format by replacing unsafe ASCII characters with a "%" followed by two hexadecimal digits.

The Web page query probably cannot contain space and encoding normally replaces a space with a plus (+) sign or with %20. (your browser link displays  Notre%20Dame%20Paris   not Notre Dame Paris.

Your browser probably does the conversion automatically, with calling the url from App Inventor, you probably have to encode.

Try encoding.  What happens?


Regards,

Steve


SteveJG

unread,
Nov 22, 2019, 9:23:56 AM11/22/19
to MIT App Inventor Forum
What exactly are you trying to do with the Nominatim Search Engine Marco?    The url you provide is a link to the search engine, it is not the raw geojson.

The url you attempt to grab a feature collection from while " triyng to make a simple geocoding app."    displays like this in a browser:

notreDameParis.PNG


 The link does not provide a FeatureCollection in the form needed by MIT's Map component.

Instead of using a Web component;  use a WebViewer to display your search using Nominatim and it will display like this on your device:

ND.jpg


Set your Project ScreenOrientation to Landscape and use the following code with a WebViewer

zzzNDparis.PNG



Type  notre dame paris   into the TextBox and press Button2

Is this really what you expect to happen and what you want to do or something else Marco?


Regards,
Steve





Message has been deleted

Marco Perrone

unread,
Nov 22, 2019, 5:33:29 PM11/22/19
to mitappinv...@googlegroups.com
Hi SteveJG,
thank You for your answer I will use Uriencode it will be very useful.
What I am trying to do:
1 The user write an address in the Textbox.
2 I send the request to the nominatin.openstreetmap
3 I receive the answer json formatted ( I use an url like the second provided in my forst post format=json)
4 I use the JsonTextDecode an look up in pairs to retreive the latitude and longitude
5 I use Map to create a Marker and a PanTo to show the address in a Map

The image attached show You what i described and it works, but sometimes (without change the address I have an empty answer, aht responsecode is correct 200)
gottext.png

SteveJG

unread,
Nov 23, 2019, 9:16:16 AM11/23/19
to MIT App Inventor Forum
Hi Marco,

A possible explanation of why sometimes you can sucessfully connect to Nomiatim and sometimes you cannot  https://operations.osmfoundation.org/policies/nominatim/  


 I can infrequently access the server using the Web component, mostly I cannot.  When I connect, I get a 200 message; when I cannot connect I don't even receive an error message. Why this happens is probably an issue of limited capacity of the server to process requests. See the top link.

-- Steve

Marco Perrone

unread,
Nov 26, 2019, 11:33:42 AM11/26/19
to MIT App Inventor Forum
Thank You SteveJG,
I will use another geocoding service to find the coordinates
Best Regards
Marco
Reply all
Reply to author
Forward
0 new messages