/**
   * Queries the plan.epfl.ch website and return the results
   *
   * @param text the query.
   * @param max the maximum number of results.
   */
  public static List<MapItem> searchTextOnEpflWebsite(String text, int max) {
    List<MapItem> list = new LinkedList<MapItem>();
    URL searchUrl;
    try {
      searchUrl = new URL("http://plan.epfl.ch/search?keyword=" + URLEncoder.encode(text, "UTF-8"));
    } catch (MalformedURLException e) {
      e.printStackTrace();
      return list;
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      return list;
    }

    Gson gson = new Gson();

    try {
      InputStreamReader reader = new InputStreamReader(searchUrl.openStream());
      BasicSearchResponse response = gson.fromJson(reader, BasicSearchResponse.class);
      if (response != null && response.features != null) {
        for (int i = 0; i < response.features.length && i < max; i++) {
          GeometryR geometry = response.features[i].geometry;
          SearchProperties properties = response.features[i].properties;
          if (geometry != null && properties != null) {
            String description = null;
            if (properties.room != null && properties.room.length() > 0) {
              description = properties.room;
            }

            double longitude = CoordinateConverter.convertEPSG4326ToLon(geometry.coordinates[0]);
            double latitude = CoordinateConverter.convertEPSG4326ToLat(geometry.coordinates[1]);

            MapItem mapItem = new MapItem(properties.text, latitude, longitude, -1, -1);
            if (description != null) {
              mapItem.setDescription(description);
            }

            try {
              int floor = Integer.parseInt(properties.floor);
              mapItem.setFloor(floor);
            } catch (Exception e) {
            }

            mapItem.setCategory(properties.category);

            list.add(mapItem);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      return list;
    }
    return list;
  }