2024 Apr 24
3:17 AM
- last edited on
2024 May 02
8:19 AM
by
Dan_Wroblewski
The challenge is now over. See our wrap-up blog.
In Task 3 of our challenge, you added theme, styles, and layout design for a new but otherwise empty app. This week, you’ll connect the app to Foursquare APIs and enable native mobile capabilities to end up with an app for finding activities near your area.
You’ll need to have done Task 3 first, or at least download the skeleton app.
The challenges so far:
________________________________________________________________________________
There are few readily available native device capabilities in SAP Build Apps which can be found by invoking the logic canvas from the lower drawer once you click on a control such as a Button.
Scan QR/barcode, Take Photo and GPS Location are native device capabilities provided by SAP Build Apps.
The output from these flow functions can be sent to an API to retrieve more information or for further processing.
In this task, we want you to explore the GPS location (latitude, longitude) capability to find user’s location, send it to Foursquare’s Place Search API to get and display places near the user. You will add logic to the place of interest buttons (Cafes, Movies, Bars, Restaurants) to retrieve the Places Search API response by providing a search query and the latitude and longitude obtained from the GPS Location.
Foursquare: Sign up for a foursquare account and get started with the Places API. Skip the “Apply for Movement SDK Access” step as it is not required for this task. Login to your foursquare account, create a project and generate an API key to access Places API as described here. In this task, we will use Place Search API using the Latitude/Longitude as described here.
1.Sign up
2.Login
3. Create Project
4. Generate an API Key
SAP Build Apps: To learn more about how to connect to REST APIs, use page, data, app variables and page parameters used in this task, you can use the references below:
In Part I, we want you to hook up the app to the Foursquare Place Search API and make it so that when the user clicks one of the buttons, say Cafes, the app will show a list of cafes.
In Part II, we want you to enhance the Details page with Photos and Address received from Get Photos API, Get Place Details API as well as add a custom logic to calculate the user’s distance from the selected place.
The skeleton app already has 2 pages (Homepage and Details page) with a basic structure of the pages. You just need to do the following:
Rest API Direct Integration
Configure REST API
Note: The query and ll query parameters configured for the REST API in the data tab should be non-static, optional value as it will be coming from the Build Apps based on the selection of buttons and latitude/longitude respectively.
Tips:
2. Save the solution: Be sure to set your community id as the app variable on this app if it is not already set. Provide the name of the main object that stores the readings such as accelerometer, barometer, compass, geolocation etc. from device sensors, as the value(maintain the case sensitivity) for String to Hash input field on the Generate Hash page and generate a hash. Hint: You can explore this object in the Formula Editor of SAP Build Apps. Take a screenshot of the homepage, save it along with the hash. You might need it to submit later.
There is a Details page provided in the skeleton app.
Below is a sample reference function that returns true/false based on calculations to determine if the user is near to a location. For our task, we want to display the distance, a user is from a venue, by clicking the Check distance button. Use formulas in SAP Build Apps to achieve this functionality. Display the distance in km in the placeholder text provided below the button.
function arePointsNearBy(currentLocation, venueLocation, km) {
var ky = 40000 / 360;
var kx = Math.cos(Math.PI * venueLocation.lat / 180.0) * ky;
var dx = Math.abs(venueLocation.lng - currentLocation.lng) * kx;
var dy = Math.abs(venueLocation.lat - currentLocation.lat) * ky;
return Math.sqrt(dx * dx + dy * dy) <= km;
}
To implement the check-in functionality, we could use true/false to determine if we can allow the user to check in. We will not be implementing the check-in functionality as part of this task.
Post a reply with the following:
Task 4 – Part 1 output
Task 4 – Part 2 output
If you have reached till here, Nice Work! You have now completed Week 4 of Developer’s challenge successfully.
Thanks for participating and enjoy using the app to search for places of interest! Feel free to add in the comments any improvements you can think of on the app or mention the parts of the exercise you found to be tricky.
2024 Apr 24 9:36 AM
Hello,
I am referring my message with this note.
Note: The query and ll query parameters configured for the REST API in the data tab should be non-static, optional value as it will be coming from the Build Apps based on the selection of buttons and latitude/longitude respectively.
Here it is mentioned that query and ll(longitude and lattitude) will be coming from build apps. I understand about the query since we will be clicking on the 4 buttons and that will act as a query, but for ll, is there a piece of logic I am missing or is it not specified here, that from where we will get it dynamically? Please suggest. Thanks.
2024 Apr 24 9:45 AM - edited 2024 Apr 24 9:45 AM
Good question, the format required for ll is specified in the foursquare api documentation. It has to be constructed using formulas using the values obtained from GPS location flow function.
2024 Apr 24 9:47 AM
2024 Apr 24 3:09 PM
2024 Apr 24 5:02 PM
The size is missing between the icon prefix and icon suffix.
2024 Apr 24 7:14 PM
2024 Apr 24 4:34 PM - edited 2024 Apr 25 7:44 AM
2024 Apr 25 7:45 AM - edited 2024 Apr 25 7:45 AM
2024 Apr 24 11:49 PM
Task 1 :
af2ca8080378cc8aeb30659effa1a806258690b66264cef0c352302359392f30
2024 Apr 25 6:03 AM - edited 2024 May 08 12:37 PM
Part 1 Results:
a8298fcd12163b85448bca8a8265e8b2456e15a12f226bba1cc18cfdb4f6b9a6
Part 2: Tried to fetch pictures of location. Not yet tried the distance part.
2024 Apr 29 8:03 AM
The homepage list icon is a "Croissant" or some sea food?
2024 May 08 12:29 PM
2024 Apr 25 7:53 AM
Hello,
I have an issue calling the test API call from the BUILD apps. When i try to do the GET Collection call, I could see the data being returned in the Network tab of the browser, but in the BUILD apps preview it was giving this error. Can anyone suggest how to resolve this?
I provided the required Header and Query parameters. Following is the URL i am using.
2024 Apr 25 7:58 AM
Hello,
tips for find the solution :
>> The GET_COLLECTION wait an array, analyse the json result, and you can see you have not an array. So to resolve this problem, you need to address the correct path in the response to get an array directly. 😉
2024 Apr 25 8:01 AM
@Jonathan_Fr thanks.
@YogSSohanee If the API does not return a list, SAP Build Apps does not automatically know which list inside the response is the one you want so you have to tell it, in the response key path field (just a JavaScript notation from the root of the response).
2024 Apr 25 8:38 AM
Great... thanks both of you for your quick responses. I will check this out. 👍
2024 Apr 25 2:44 PM
I couldn't wrap my head around this part, until I found this link : https://www.youtube.com/watch?v=hNkIDQMfYsI
@Jonathan_Fr & @Dan_Wroblewski explained it pretty well, but this video linked up everything. Maybe it helps 😁
2024 Apr 25 9:24 AM - edited 2024 Apr 25 10:31 AM
Must be missing something basic here, created an account with foursquare yesterday buttons are greyed out:
UPDATE: Personal e-mail works.
2024 Apr 25 9:28 AM - edited 2024 Apr 26 12:35 PM
f9f0589a14f65073eff138d8c27cac3a7580153db54ac2b245d35d3fd9a965e6
EDIT: updated with Part 2
2024 Apr 25 4:02 PM
Hi @eshrinivasan ,
Hash:
7d594987ae0ad529bc58307313dcf02bcaa93b4e75421c7da8349f6fc486a29f
Task1:
Movies
Cafes
Detail Page
One Request : Why the build app is not allowed to take screenshot. I am using Android Phone. Hope it is allowed in future.
2024 Apr 25 4:04 PM
0798a81544bd60221943b2c4183dd08945f88fee4d381466703bded8a9f2a8d5
Will update my response after I complete part II (still have to figure out how to fetch all the photos from the API 😅)
2024 Apr 25 9:54 PM - edited 2024 Apr 26 10:28 PM
Part 1 :
Hash - c79825a95ae8ecf0946c4d0892af3565cae3ae916806fcbc79ae7fd5e3462508.
Part 2 :(Updated)
wow.. that took some digging through the settings :-D. Really helpful though to get a deep understanding of the Build apps terminologies.
2024 Apr 26 12:49 PM
Hello guys,
I would have 2 questions regarding part 2 of the challenge :
2024 Apr 27 8:55 PM - edited 2024 Apr 27 8:55 PM
Is there any error on network call while calling the photos api in the web preview? Sometimes i observed that the location data doesnt get passed correctly to the API and then it doesnt return the photos data. If this happens, then you just need to close the browser and open again, so that it will again ask you for the location access permission popup.
Another way to check during the app execution is to put a JS after the data variable assignment in the logic canvas, and in the JS, capture the data variable as a input parameter and then in the JS put a console log to check if the data variable is being populated with correct data or not. The reason for putting console log in the JS is that sometimes it doesnt load the input parameter variables correctly in the JS if the context of those variables are not specified somewhere in the JS.
For the 2nd point, can you show the error that you are getting with "distance_calculated" Page Variable?
2024 Apr 28 11:07 AM
It's very strange, in the sense that, whenever I click on one of the places loaded, the Get Photos API call is not getting triggered (nothing shows up in the Network tab of the DevTools; for the Get Details, there is a call and the details of that particular location are loaded). However, when I'm editing it in the UI Canvas, photos of a sample location are loaded.
Regarding point 2 : I also tried adding the formula @Dan_Wroblewski used, but now, when I click the button, nothing is happening.
2024 Apr 28 11:18 AM
Hi ,
Couple of things to check:
1) Whether the page parameters are getting passed correctly from home page and make sure they have the same name as you have defined them in the details page.
2) On the details page, where you setting your data variable with the Get Record Collection in the logic canvas of the data variable, try to put a JS after the "Get Record Collection" and observe if the API call is happening correctly or not. Also while the data variable gets called, the fsq_id gets passed, so pay attention if the fsq_id is getting passed correctly or not. This is where the page parameters will play an important role.
2024 Apr 28 11:31 AM
Couple of holes I fell into:
Just take it step by step in order to debug, for example:
2024 Apr 28 12:31 PM
Thank you @YogSSohanee & @Dan_Wroblewski for the help. As it turns out, I didn't maintain the fsq_id for the Photos API (for the Details API it was maintained) 🙈
Regarding part 2 : I manage to return the correct distance (I see that from an Alert in the Logic Canvas), however, the description is not getting updated with the updated page variable. I guess I'll have to do a Javascript to update that particular text
2024 Apr 26 1:35 PM
Halfway there:
c3b709a933a9a4b43d55a03a305ad9dd13c5e97b01f4286ca47a8a0c7124686e
2024 Apr 26 5:57 PM
2024 Apr 27 6:23 PM
Worth noting that needed to call the GPS function on both screens.
2024 Apr 26 3:26 PM
Hello Team,
Here is my sumission for part 1
Hash: 3e51094ff247d6c9f584d70ca5886434a135a3b252a184ea3e12d3429be53493
Screenshot:
2024 Apr 28 5:39 AM
2024 Apr 29 7:54 AM - edited 2024 Apr 29 7:55 AM
Hey Dan,
Here is screenshot of my Hash Screen, i am still getting the same hash
3e51094ff247d6c9f584d70ca5886434a135a3b252a184ea3e12d3429be53493
Also, i am facing some issue while trying to create formula for web-url of the image, getting a 404 on the network
2024 Apr 29 8:38 AM
For the string to hash variable, you might want to look into the actual system variable you are using in the formula for getting all the sensor data. The one you have maintained in the string to hash field is not correct.
And for the URL, the size for the photo seems to be missing in the formula. Please refer to this Assemble_photo_URL . Hope this will be useful.
2024 Apr 29 2:35 PM
Thanks a lot for your inputs @YogSSohanee .
Here is my updated Hash: 17d8962a1151562cf14e6b6c6acb775846f68a2c8741e1ffb737d4568e20b730
2024 Apr 30 5:45 AM
2024 Apr 30 12:52 PM
Hello All,
Here is the Check Distance Functionality with a javascript function for now.
And here is my Hash Page, hope it is correct now
Hash : bcb9d15e59a98b1eb0c3e09d68541e04f2664adcea09bae78ae18ac3289ddf6b
2024 Apr 30 8:29 AM
Hi Vaibhav, still the hash seems incorrect. Remember it is an object name and it has to be exactly as shown in the formula editor.