Esempio n. 1
0
  /**
   * 最寄りの施設をさがす.<br>
   *
   * @author n-yuuta<br>
   * @param lan 経度<br>
   * @param lon 緯度<br>
   * @return building
   */
  public Building getNearestBuilding(double longitude, double latitude) {

    int minBuildId = 0;
    double minLan = 0.0;
    double minLon = 0.0;
    int minCount = 0;
    String minName = "";

    double minDistance = 0.0;
    double distance = 0.0;

    ArrayList<Building> buildingList = DBUtils.convertDBToBuildingList();

    for (int i = 0; i < buildingList.size(); i++) {

      distance =
          this.calcDistance(
              longitude,
              latitude,
              buildingList.get(i).getLongitude(),
              buildingList.get(i).getLatitude(),
              5);

      if (i == 0) {
        minDistance = distance;
        minBuildId = buildingList.get(i).getBuildId();
        minLan = buildingList.get(i).getLongitude();
        minLon = buildingList.get(i).getLatitude();
        minCount = buildingList.get(i).getCount();
        minName = buildingList.get(i).getName();

      } else {
        if (distance < minDistance) {
          minDistance = distance;
          minBuildId = buildingList.get(i).getBuildId();
          minLan = buildingList.get(i).getLongitude();
          minLon = buildingList.get(i).getLatitude();
          minCount = buildingList.get(i).getCount();
          minName = buildingList.get(i).getName();
        }
      }
    }

    Building building = new Building();
    building.setBuildId(minBuildId);
    building.setLongitude(minLan);
    building.setLatitude(minLon);
    building.setCount(minCount);
    building.setName(minName);

    return building;
  }
Esempio n. 2
0
  /**
   * 近くの施設をまとめて返す(おそらく正式に使うBuildingList版)
   *
   * @author 2015020 賀数
   * @param lon 緯度
   * @param lat 経度
   * @return 施設群
   */
  public BuildingList searchBuildings(double longitude, double latitude) {
    BuildingList buildingList = new BuildingList();

    List<Building> buildings = new ArrayList<Building>();

    DBCursor cursor = coll.find(new BasicDBObject());

    buildingList.setBuildNum(cursor.count());

    for (DBObject test : cursor) {
      Building bld = new Building();
      bld.setBuildId((int) test.get("buildId"));
      bld.setCount((int) test.get("count"));
      bld.setLatitude((double) test.get("latitude"));
      bld.setLongitude((double) test.get("longitude"));
      bld.setName((String) test.get("name"));

      buildings.add(bld);
    }

    buildingList.setBuildings(buildings);

    return buildingList;
  }