示例#1
0
 /*
 Given two buildings, filterout all places within given range
  */
 private void displayAllPlacesWithinRange(Building building1, Building building2, int range) {
   PlaceFactory places = PlaceFactory.getInstance();
   Set<Place> places1 = places.findPlacesWithinDistance(building1.getLatLon(), range);
   Set<Place> places2 = places.findPlacesWithinDistance(building2.getLatLon(), range);
   List<Place> placesWithinRange = new ArrayList<Place>();
   for (Place p : places1) {
     if (places2.contains(p)) {
       placesWithinRange.add(p);
     }
   }
   plotPlaces(placesWithinRange);
 }
示例#2
0
 protected void onPostExecute(String jSONOfPlaces) {
   // CPSC 210 Students: Given JSON from FourQuest, parse it and load
   // PlaceFactory
   JSONObject obj = null;
   try {
     obj = new JSONObject(jSONOfPlaces);
     JSONObject response = obj.getJSONObject("response");
     JSONArray items = response.getJSONArray("groups").getJSONObject(0).getJSONArray("items");
     for (int i = 0; items.length() > i; i++) {
       // parse out the info needed to construct a eating place
       String name = items.getJSONObject(i).getJSONObject("venue").getString("name");
       Double lat =
           items
               .getJSONObject(i)
               .getJSONObject("venue")
               .getJSONObject("location")
               .getDouble("lat");
       Double lng =
           items
               .getJSONObject(i)
               .getJSONObject("venue")
               .getJSONObject("location")
               .getDouble("lng");
       // construct eating place
       EatingPlace ep = new EatingPlace(name, new LatLon(lat, lng));
       // add eating place to placefactory
       PlaceFactory places = PlaceFactory.getInstance();
       places.add(ep);
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
   // Display how many places added to the placefactory
   int num = PlaceFactory.getInstance().getNumberOfPlaces();
   AlertDialog aDialog = createSimpleDialog("Found " + num + " Places near UBC");
   aDialog.show();
 }