/** * 最寄りの施設をさがす.<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; }
/** * 近くの施設をまとめて返す(ArrayList版。使用しなくなる予定) * * @author 2015020 賀数 * @param lon 緯度 * @param lat 経度 * @return 施設群 */ public ArrayList<Building> getNearBuildings(double lon, double lat) { ArrayList<Building> buildingList = DBUtils.convertDBToBuildingList(); // 離れた施設は除外 double removeDist = 0.5; int size = buildingList.size(); for (int i = 0; i < size; i++) { Building target = buildingList.get(i); if (Math.abs(lat - target.getLatitude()) > removeDist || Math.abs(lon - target.getLongitude()) > removeDist) { buildingList.remove(i); i--; size--; } } return buildingList; }
/** Logger、DB、DBCollectionフィールドに各オブジェクトを設定する. */ public BuildingModel() { db = jp.cspiral.c6.shareUmbrella.util.DBUtils.getInstance().getDb(); coll = db.getCollection(DB_BUILDING_COLLECTION); }