// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* global google */

if(document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', initialize);
} else {
  initialize();
}

let map;
let placesService;
let randomLocation;

/**
 * Initializes the webpage with a map and random location
 */
function initialize() {
  randomLocation = new google.maps.LatLng(33.4806, -112.1864);
  map = new google.maps.Map(document.getElementById('map'), {
      center: randomLocation,
      zoom: 15
  });
  //placesService = new google.maps.places.PlacesService(map);
}
@@ -779,16 +779,103 @@
 ocation;
+%0Alet RADIUS = 1000; // Measured in meters%0Alet interests = %5B%22bank%22, %22groceries%22, %22park%22%5D
 %0A%0A/**%0A *
@@ -909,20 +909,17 @@
 th a map
- and
+,
  random 
@@ -927,16 +927,63 @@
 ocation%0A
+ * and recommendations based on user interest.%0A
  */%0Afunc
@@ -1184,66 +1184,1395 @@
 ;%0A  
-//placesService = new google.maps.places.PlacesService(map);%0A%7D
+placesService = new google.maps.places.PlacesService(map);%0A  loadRecommendations();%0A%7D%0A%0A/**%0A * Go through a user's interests and find places%0A * fitting the interests with the textSearch method.%0A */%0Afunction loadRecommendations() %7B%0A  interests.forEach(placeType =%3E %7B%0A      console.log(placeType);%0A      let request = %7B%0A        location: randomLocation,%0A        radius: RADIUS,%0A        query: placeType%0A      %7D;%0A      placesService.textSearch(request, addRecommendations);%0A  %7D);%0A%7D%0A%0A/**%0A * Checks the response from PlacesService and creates markers%0A * on the locations found from the request. Temporarily limit%0A * the amount of markers added.%0A * TODO: Load all results, but have a list that limits the results%0A * shown rather than limiting the results being loaded.%0A * @param %7BPlaceResults%5B%5D results%7D places found with PlaceResult type.%0A * @param %7BPlacesServiceStatus status%7D status of PlacesService request.%0A */%0Afunction addRecommendations(results, status) %7B%0A  if (status == google.maps.places.PlacesServiceStatus.OK) %7B%0A    let maxRecommendations = 3;%0A    let numRecommendations = 0;%0A    for (let i = 0; i %3C results.length; i++) %7B%0A      console.log(results%5Bi%5D.formatted_address);%0A      numRecommendations++;%0A      if(numRecommendations == maxRecommendations) %7B%0A        break;%0A      %7D%0A    %7D%0A  %7D else %7B%0A    alert(%22Status: %22 + status +%0A          %22%5CnOur services are currently down. Oops!%22);%0A  %7D%0A%7D%0A

Add textSearch to find recommendations that fit the interests provided. Temporarily limit results