Display web service results on a form

53 views
Skip to first unread message

Yahya-Imam Munir

unread,
Jun 14, 2017, 6:59:48 AM6/14/17
to CodenameOne Discussions
Hi Shai, after watching these videos (http://www.codenameone.com/blog/propertycross-demo.html). I'm trying to do the same but i'm finding it very difficult as i'm using the old GUI Builder. I created a form called Form A. I want those results from the web service to display on the form A and be able to navigate upon clicking any of those images just like what you did in the video. I'm using the following methods: private Map response; @Override protected void beforeFormA(Form f) { getattractive(); ArrayList arr = (ArrayList) response.get("results"); for (Object m:arr){ Map ma = (Map)m; address =(String) ma.get("formatted_address"); findContainer(f).addComponent(new Label(""+ address )); } } Connection Request: private void getattractive(){ ConnectionRequest r= new ConnectionRequest(){ @Override protected void readResponse(InputStream input) throws IOException { JSONParser parse= new JSONParser(); response= parse.parseJSON(new InputStreamReader(input)); } }; String doc="Johor"; r.setUrl("https://maps.googleapis.com/maps/api/place/textsearch/json?query="+doc+"+city+point+of+interest&language=en&key=api_key"); r.setPost(false); r.setHttpMethod("GET"); InfiniteProgress prog=new InfiniteProgress(); Dialog dlg=prog.showInifiniteBlocking(); r.setDisposeOnCompletion(dlg); NetworkManager.getInstance(). addToQueueAndWait(r); } First record from the webservice: { "html_attributions" : [ "Listings by \u003ca href=\"http://www.openrice.com/\"\u003eOpenRice\u003c/a\u003e" ], "results" : [ { "formatted_address" : "Jalan Gertak Merah, 80000 Johor Bahru, Johor, Malaysia", "geometry" : { "location" : { "lat" : 1.4575491, "lng" : 103.7523184 }, "viewport" : { "northeast" : { "lat" : 1.458888830291502, "lng" : 103.7536227802915 }, "southwest" : { "lat" : 1.456190869708498, "lng" : 103.7509248197085 } } }, "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", "id" : "7c6808053578e235889ea4fb585d43f1fdb25683", "name" : "Zoo Johor", "opening_hours" : { "open_now" : true, "weekday_text" : [] }, "photos" : [ { "height" : 2592, "html_attributions" : [ "\u003ca href=\"https://maps.google.com/maps/contrib/105088801807714473130/photos\"\u003e中島將貴\u003c/a\u003e" ], "photo_reference" : "CmRaAAAAAMaIKm8L8gVpId5ycP6xJSZgz_rQfQowXLo9xcBbjh310zCwISl4ZyX4djRDSra47BiqFhS-35BG8_v-VC3VK0axftevzVRiKSS3MFmrXATwpeGHRe1JroI0vckE8BYXEhB_SenVoqIYPDbu89ebPrXAGhQBZEij_vsj3pAwcj5mYjAkw1sPcQ", "width" : 3872 } ], "place_id" : "ChIJpTA-wsAS2jERtAhAlaGjg6g", "rating" : 3.7, "reference" : "CmRSAAAAAsAK89IFfD85of_OzBiU0JRBp-MeVHZKrbZv8xk-VMhDtDGF-1T0fzpAweqy4NCAjCmYCHSHnT7y4hB2zcAhfKmtB456EtgKt2EPF2QgagFa_-jNZaykEtEpp21-RXYgEhBLUEYJiUVsN8h_P7ltXzSPGhTEwnIwCBsBk6VyIL6PXu8qZ1IkMg", "types" : [ "zoo", "point_of_interest", "establishment" ] } Please kindly help. Regards,






IDE: NetBeans
Desktop OS: Windows 7
Simulator

Shai Almog

unread,
Jun 15, 2017, 12:16:56 AM6/15/17
to CodenameOne Discussions

Yahya-Imam Munir

unread,
Jun 15, 2017, 4:11:21 AM6/15/17
to CodenameOne Discussions
@ShaiAlmog thanks for your response. I did as instructed but I didn't find anything that could lead me to what you had in that video. I saw all the variables I declared, the information inside the connection request method  and some other things which I don't really know how they work. Please see the attached picture.


Regards,

On Thursday, June 15, 2017 at 12:16:56 PM UTC+8, Shai Almog wrote:
Slide.png

Yahya-Imam Munir

unread,
Jun 19, 2017, 7:10:42 AM6/19/17
to CodenameOne Discussions

@Shai thanks for your response. I did as instructed and I found all the returned values. Please see the attached pictures (picture 1-4).

I want to display the picture, name, address, and opening hours in a layout similar to what you have in the video (pls see image1). I was able to display the name and address (pls see image) but I still have issues with the layout and how to display the picture and opening hours.  Additionally, I want when I click on the picture it should open a map and show the location. 


Any assistance on these would be appreciated. 

1.png
4.png
image.png
image1.png
2.png
3.0.png
3.1.png
3.2.png
3.3.png
3.4.png
3.5.png
3.6.png

Yahya-Imam Munir

unread,
Jun 20, 2017, 11:07:32 PM6/20/17
to CodenameOne Discussions
@ShaiAlmog thanks for your supports. I tried to inspect the variable as instructed but i'm getting thesame result like the ones i posted previously. Please see the attached pictures.

debug picture: before the request was made to the web service.

debug1 picture: after the request was made.

debug2 picture: after entering "response" in the watch space  
debug.png
debug1.png
debug2.png

Shai Almog

unread,
Jun 21, 2017, 1:34:29 AM6/21/17
to CodenameOne Discussions

Yahya-Imam Munir

unread,
Jun 21, 2017, 6:14:46 AM6/21/17
to CodenameOne Discussions
Hi Shai, thanks for the supports. Yes I did as instructed and it returned the exact records (please see image2) . When I expand them I got the same keys and values i had previously. The JSON results came from this webservice: https://maps.googleapis.com/maps/api/place/textsearch/json?query=Johor+city+point+of+interest&language=en&key=AIzaSyDVw0z5f4MNN-t1zI2N3bBIcWX4D3Kp3mE
image2.png
Message has been deleted

Yahya-Imam Munir

unread,
Jun 22, 2017, 7:06:52 AM6/22/17
to CodenameOne Discussions
Hi Shai, Thanks for your response. What i'm trying to do is to have the output layout like this (please see image3). Currently i'm having this (please see image) and whenever i click on the image i want it to open up the location on a map.

Below is my code:


@Override
    protected void beforeFormA(Form f) {
     getattractive();
         ArrayList arr = (ArrayList) response.get("results");                
                for (Object m:arr){                  
                Map ma = (Map)m;              
                Container c1 = new Container(new BoxLayout(BoxLayout.Y_AXIS));                     
                address =(String) ma.get("formatted_address");
                name=(String)ma.get("name");
                c1.addComponent(new Label(""+ name ));
                c1.addComponent(new Label(""+ address ));
                findContainer(f).addComponent(c1);                   
    }         
}






On Wednesday, June 21, 2017 at 6:29:47 PM UTC+8, Yahya-Imam Munir wrote:
What i'm trying to do is to have the output layout like this (please see image1). Currently i'm having this (please see image) and whenever i click on the image i want it to open up the location on a map.
image.png
image3.png
Reply all
Reply to author
Forward
0 new messages