2014년 11월 28일 금요일

Working with Google Places API & MIT Inventor-Issue


I have successfully created a test project that takes the following Google Place API address and outputs the name of the store from preset coordinates, on to screen1. This project is only a test! I now would like  to figure out how I can display more then one store name from Google Places API. For example, right now the coordinates predefined are for a area full of stores in Scranton PA. As you can see going to the Google Places API address I have produced below, the first name shown is Gander Mountain. However, these are other names of stores listed on the Google Places API address. For some reason I can only output one store name. I'm trying to output more then one store name to each label. Is this possible.?

Note: Key will be expired in a couple of days. Please use your own if needed. The address is correct..

Google Places API:


I have attached my test project (aia). Any help would be great


--
see  my answer here http://stackoverflow.com/a/27158968/1545993


convert the JSON result into a list of lists, then loop through one of the inner lists, which provide your results. It also helps to use Do it to debug your blocks...
In the test I used a 3 element JSON result, therefore you get only 3 names in the result list.



Edit: solution to assign the result to different labels 

--
If I wanted to output 1 result per Label#.text, would I change the index to 1 and ? Example output 3 results to Label1.text, Label2.text,Lablet3.text. What is the point of the index number?

--
Yes, you can do this, just use the advanced label blocks. However, you can't create components dynamically, you have to create as many labels as you may need before. See an example, which uses the advanced button blocks here
--
From the example above, I am getting an error at runtime:Select list item: Attempt to get item number 4 of a list of length 3: (com.google.appinventor.components.runtime.Label@431260a0 com.google.appinventor.components.runtime.Label@43128b48 com.google.appinventor.components.runtime.Label@4312a948) --- WhenI select "Do it" I see that the select list item cannot accept argument. Which I believe would be the .JsonDevode jsonText. I'm going to try it a different way, but I just wanted to let you know.
-- 
yes, I did not add data validation. If you only have 3 labels, you will get an error if you try to assign the 4th value, just add an if statement: if index <= length of list (list) then set label.Text ...

--

댓글 없음:

댓글 쓰기