@GET @Path("getPOIInRadius/{lng}/{lat}/{radius}") @Produces("application/json; charset=UTF-8") public String getPOIInRadius( @PathParam("lng") double lng, @PathParam("lat") double lat, @PathParam("radius") double radius) { List<POI> list = poiDAO.getAllPOIs(false); List<POIClient> inRadiusList = new ArrayList<POIClient>(); GeoLocation centerGeo = new GeoLocation(lat, lng); for (POI poi : list) { List<GeoLocation> geoList = GeoUtil.toLatLng(poi.getGeometry()); for (GeoLocation geoLocation : geoList) { double distance = GeoUtil.caculateDistance(centerGeo, geoLocation); if (distance <= radius) { POIClient poiClient = new POIClient(); poiClient.setId(poi.getId()); poiClient.setName(poi.getName()); poiClient.setCategory(poi.getCategoryName()); poiClient.setAddress(poi.getAddress()); poiClient.setCity(poi.getCityName()); poiClient.setDistrict(poi.getDistrictName()); poiClient.setDescription(poi.getDescription()); poiClient.setImage(urlHost + poi.getImage()); poiClient.setMarkerIcon( urlHost + categoryDAO.getCategoryById(poi.getCategoryID()).getImage()); poiClient.setGeometry(poi.getGeometry()); poiClient.setRating(poi.getRatingName()); poiClient.setCreatedOnDate(poi.getCreatedOnDate()); poiClient.setDistance(distance); inRadiusList.add(poiClient); break; } } } // sort inRadiusList Collections.sort( inRadiusList, new Comparator<POIClient>() { @Override public int compare(POIClient p1, POIClient p2) { int kq; if (p1.getDistance() > p2.getDistance()) { kq = 1; } else { kq = -1; } return kq; } }); return new Gson().toJson(inRadiusList); }
@GET @Path("getAll") @Produces("application/json; charset=UTF-8") public String getAll() { List<POI> list = poiDAO.getAllPOIs(false); List<POIClient> listPOIClients = new ArrayList<POIClient>(); for (POI poi : list) { POIClient poiClient = new POIClient(); poiClient.setId(poi.getId()); poiClient.setName(poi.getName()); poiClient.setCategory(poi.getCategoryName()); poiClient.setAddress(poi.getAddress()); poiClient.setCity(poi.getCityName()); poiClient.setDistrict(poi.getDistrictName()); poiClient.setDescription(poi.getDescription()); poiClient.setImage(urlHost + poi.getImage()); poiClient.setMarkerIcon( urlHost + categoryDAO.getCategoryById(poi.getCategoryID()).getImage()); poiClient.setGeometry(poi.getGeometry()); poiClient.setRating(poi.getRatingName()); poiClient.setCreatedOnDate(poi.getCreatedOnDate()); listPOIClients.add(poiClient); } return new Gson().toJson(listPOIClients); }