Example #1
0
 /**
  * Method takes a base address and establishments and return the addresses
  *
  * @param baseLocation
  * @param establishmentType
  * @return allResults
  */
 public static String[][] GetAddresses(String baseLocation, String[] establishmentType) {
   PlacesSearchResponse responses;
   String[][] allResults = new String[establishmentType.length][];
   for (int type = 0; type < establishmentType.length; type++) {
     try {
       responses =
           PlacesApi.textSearchQuery(context, establishmentType[type] + " near " + baseLocation)
               .await();
       allResults[type] = new String[responses.results.length];
       for (int i = 0; i < responses.results.length; i++) {
         PlacesSearchResult result = responses.results[i];
         allResults[type][i] = (result.name + " " + result.formattedAddress);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return allResults;
 }
Example #2
0
 /**
  * returns the travel times of a jagged array of destinations in a sorted manner by duration
  *
  * @param startAddress the base address
  * @param destinations the places under examination
  * @return
  */
 public static String[][] TravelTime(String startAddress, String[][] destinations) {
   String[] startAddressArr = new String[1]; // need an array of size 1 to hold the base address
   startAddressArr[0] = startAddress; // set the only element to the base address
   String[][] fastest =
       new String[destinations.length]
           []; // fastest is the jagged array which will hold the ordered destinations
   for (int destinationIndex = 0;
       destinationIndex < destinations.length;
       destinationIndex++) // go through each destination type
   {
     try {
       DistanceMatrix distances =
           DistanceMatrixApi.getDistanceMatrix(
                   context, startAddressArr, destinations[destinationIndex])
               .await(); // get the matrix from google
       // TODO MAKE THIS ONE API CALL!!!
       distances =
           SortByFastest(
               distances, destinations[destinationIndex]); // call a method to sort this matrix
       fastest[destinationIndex] =
           new String
               [destinations[destinationIndex]
                   .length]; // make fastest of a certain type equal to the length of  the number
                             // of destinations
       for (int place = 0; place < destinations[destinationIndex].length; place++) {
         for (int search = 0; search < destinations[destinationIndex].length; search++) {
           fastest[destinationIndex][place] =
               distances.destinationAddresses[place]
                   + " is "
                   + distances.rows[0].elements[place].duration
                   + " away"; // set it equal to the travel time
           break;
         }
       } // loading up the array based on this info
     } catch (Exception e) {
       e.getStackTrace();
     }
   }
   return fastest;
 }