2 weeks ago - last edited Thursday 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.
a week ago
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.
a week ago - last edited a week ago
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.
a week ago
a week ago
a week ago
The size is missing between the icon prefix and icon suffix.
a week ago
a week ago - last edited a week ago
a week ago - last edited a week ago
a week ago
Task 1 :
af2ca8080378cc8aeb30659effa1a806258690b66264cef0c352302359392f30
a week ago - last edited a week ago
Part 1 Results:
a8298fcd12163b85448bca8a8265e8b2456e15a12f226bba1cc18cfdb4f6b9a6
Monday
The homepage list icon is a "Croissant" or some sea food?
a week ago
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.
a week ago
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. 😉
a week ago
@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).
a week ago
Great... thanks both of you for your quick responses. I will check this out. 👍
a week ago
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 😁
a week ago - last edited a week ago
Must be missing something basic here, created an account with foursquare yesterday buttons are greyed out:
UPDATE: Personal e-mail works.
a week ago - last edited a week ago
f9f0589a14f65073eff138d8c27cac3a7580153db54ac2b245d35d3fd9a965e6
EDIT: updated with Part 2
a week ago
Hi @eshrinivasan ,
Hash:
7d594987ae0ad529bc58307313dcf02bcaa93b4e75421c7da8349f6fc486a29f
Task1:
One Request : Why the build app is not allowed to take screenshot. I am using Android Phone. Hope it is allowed in future.
a week ago
0798a81544bd60221943b2c4183dd08945f88fee4d381466703bded8a9f2a8d5
Will update my response after I complete part II (still have to figure out how to fetch all the photos from the API 😅)
a week ago - last edited a week ago
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.
a week ago
Hello guys,
I would have 2 questions regarding part 2 of the challenge :
Saturday - last edited Saturday
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?
Sunday
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.
Sunday
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.
Sunday
Couple of holes I fell into:
Just take it step by step in order to debug, for example:
Sunday
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
a week ago
Halfway there:
c3b709a933a9a4b43d55a03a305ad9dd13c5e97b01f4286ca47a8a0c7124686e
a week ago
Saturday
Worth noting that needed to call the GPS function on both screens.
a week ago
Hello Team,
Here is my sumission for part 1
Hash: 3e51094ff247d6c9f584d70ca5886434a135a3b252a184ea3e12d3429be53493
Screenshot:
Sunday
Monday - last edited Monday
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
Monday
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.
Monday
Thanks a lot for your inputs @YogSSohanee .
Here is my updated Hash: 17d8962a1151562cf14e6b6c6acb775846f68a2c8741e1ffb737d4568e20b730
Tuesday
Tuesday
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
Tuesday
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.
Saturday
fdf88fb3b3b2300adf61f4c9e93c68eda905374a3d68a51090ca608254bc1c54