Skip to main content

Assignment 5: Mobile Development

Due Friday, March 26 11:59pm ET

Setup

Accept the Github Classroom assignment and clone this repo that contains stencil code for Assignment 5.

Introduction

Congratulations! You’ve made it to the mobile section of CSCI 1320!

Most people use their cell phones to browse websites, check messages, send emails - you name it! Therefore, it’s extremely important that any web application is compatible for mobile devices.

Your job in this assignment is to create your very own Restaurant Finder mobile application that will potentially run on both Android and iOS devices using NativeScript, JavaScript, and CSS. (Don’t worry if you don’t have a Mac -- running it on Android as a demo is fine; as long as you don’t do anything platform specific (which is difficult), it would also run on a Mac if needed.)

Prelab and Lab 7 will be very useful in understanding and implementing this assignment. As always, don’t forget to check out the Docs page for additional resources and read through this entire handout before beginning.

You may use the NativeScript Playground and Preview to preview your app but you must download your application locally in order to hand in the files.

Important note : When you are using the NativeScript Playground, you must save your files by clicking on the Save cloud icon on the top, gray bar. NativeScript Playground does not save files automatically!

Requirements

Your Restaurant Finder app must include the following:

  • A Welcome (Home) screen displaying a menu bar with at least one button linking to a Nearby Restaurants screen
  • A Nearby Restaurants screen that uses the Google Places API to display the ten closest restaurants to the user’s current location
  • A search bar on the Nearby Restaurants screen allowing the user to search within your displayed nearby restaurants by the restaurant’s name
  • A way to return back to the Home screen from the Nearby Restaurants screen
  • An organized and clear UI (feel free to have fun with the design!)

  • Clarifications:

  • You can search and filter your displayed list of nearby restaurants only or you can use the Search API.

  • If you use the Search API (this is more complicated), then the requirements are as follows:

  • The search term should still filter through the restaurants displayed on your Nearby Restaurants page
  • For example, if the search term matches a restaurant that is currently being displayed from your initial nearby fetch, then it should still show up in the filtered results, regardless of its presence in the Search API results
  • You may get a new restaurant (a restaurant that is not in your list of 10 nearby restaurants from the initial fetch) in the Search API results - you also may get a restaurant that is already in your list of restaurants - ensure that you do not display such a restaurant twice.
  • For new restaurants that are not already in your fetched 10 nearby restaurants, you should add these restaurants to your ongoing list of restaurants, so that when you clear your search term, they are still visible in your list. Making new restaurants disappear after clearing the search would be confusing to the user.

  • We recommend not using the Search API until you have satisfied the basic functionality requirements (simply filtering through your list of 10 restaurants), since doing so adds more complexity.

    Google Places API

    See https://developers.google.com/places/web-service/overview for official documentation; we recommend referencing this throughout the project.

    We will be using the Google Places API for the Nearby Restaurants portion of this assignment. This will let us request and use data that Google Places has gathered for our own app.

    Setting up

    If you would like to develop locally, first clone the repository from Github classroom. Then, navigate into the repository and run npm install -g nativescript@latest to install the latest version of NativeScript locally. Then, run ns create to set up your local file structure. You will be prompted to name the project, choose a frontend technology, and select a template; these choices are up to your preference as a developer! To preview the application on a mobile phone, cd into your project directory (which will have the name you picked in the previous step), run ns preview, and scan the QR in the NativeScript Playground app.

    To use the Google Places API, you must have Google Maps Platform enabled. If you have not used this platform before, please refer to the following instructions:

    1. Visit Google Maps Platform . Switch to a non-Brown Gmail account.
    2. Click Get Started m choose Places , name your new project, read the terms & conditions.
    3. Create a billing account. You will receive a free, 12-month trial with $300 (trial ends when whichever is used up first) and will not be auto-billed for the next cycle unless you’ve turned on automatic billing. This assignment will not exceed $300.
    4. Fill out the survey (optional). Then click Continue and set up your API key. You can also set up API key by clicking Credentials , + CREATE CREDENTIALS , and choose API key .
    5. Key security: since we are grading on different computers, you can skip this step. In practice though, it is always highly recommended to protect your API key. You can read more on how to Add Restriction to API Keys

    Now that you have set up your account, we recommend referencing Google Places documentation to figure out which requests to use. You may need to include optional parameters.

    Finding your location

    Trying to find the nearest restaurants to you requires Google Places to know your current location. Google Places isn’t able to do this, but we can import something that can.

    To find your device’s location, import the npm module nativescript-geolocation . You can do this by clicking the + button beside the Explorer and then clicking add NPM package . This will add a folder called nativescript-geolocation to your project. To import the module in your code, use require like so:

                        
    const Geolocation = require("nativescript-geolocation");
                

    This module will let you:

    • request permission to access location data
    • retrieve location data

    To retrieve location data, you can include options or parameters to tell the module what details of the data you need returned.

                        
    getMyLocation() {
    Geolocation.enableLocationRequest();
    Geolocation.getCurrentLocation({
    desiredAccuracy: 100,
    updateDistance: 0.1,
    timeout: 20000
    }).then(
    loc => {
    if (loc) {
        // this is your location data, may need to parse
        console.log(loc);
    }
    },
    function(e) {
        console.log("Error: " + e.message);
    }
    );
    },
                        

    Then, you can pass in this location data as a parameter for your API calls, and Google Places will return restaurant data that is closest to this location.

    To read more about nativescript-geolocation, visit the official documentation . This will come in handy while completing the assignment.

    Finding nearest restaurants

    We recommend using an HTTP GET request to retrieve data from the Google API. You can set up a method (function if you do not use Vue) that does this like so:

    
    getMyRestaurants() {
    Geolocation.enableLocationRequest();
    Geolocation.getCurrentLocation({
    desiredAccuracy: 100,
    updateDistance: 0.1,
    timeout: 20000
    }).then(
    loc => {
      if (loc) {
          const key = "your api key goes here";
          const request = "your call type goes here, eg nearbysearch";
          const output = "your output type here, eg json";
          const parameters = "your parameters here";
          const url = `https://maps.googleapis.com/maps/api/place/${request}/${output}?${parameters}&key=${key}`;
    http.request({ // http is a separate module and similarly to the Geolocation module, you will need to import it by including "const http = require("tns-core-modules/http");" at the top of script
              url: url,
              method: "GET"
          }).then(this.parseResponse); // parseResponse is a method to be defined yourself
      }
    },
    function(e) {
      console.log("Error: " + e.message);
    }
    );
    },
          

    In the url http request, separate parameters with & . For example: "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=1500&type=restaurant&keyword=cruise&key=ABC123"

    Troubleshooting

    As with assignment1, it is recommended that you take advantage of all the online resources we have provided so far. If you get stuck, we would be happy to troubleshoot with you at TA hours or on Piazza!

    Hand in

    To hand in your code for Assignment 5, upload your code to Gradescope via Github repository upload (ensure that you have pushed your changes and that you are handing in the most recent version of your code!).