CoordinateBounds bounds = queryBean.getBounds();
String query = queryBean.getQuery();
int maxCount = queryBean.getMaxCount();
CoordinatePoint center = SphericalGeometryLibrary.getCenterOfBounds(bounds);
SearchResult<AgencyAndId> stops;
try {
stops = _searchService.searchForStopsByCode(query, 10, MIN_SCORE);
} catch (ParseException e) {
throw new InvalidArgumentServiceException("query", "queryParseError");
} catch (IOException e) {
_log.error("error executing stop search: query=" + query, e);
e.printStackTrace();
throw new ServiceException();
}
Min<StopBean> closest = new Min<StopBean>();
List<StopBean> stopBeans = new ArrayList<StopBean>();
for (AgencyAndId aid : stops.getResults()) {
StopBean stopBean = _stopBeanService.getStopForId(aid);
if (bounds.contains(stopBean.getLat(), stopBean.getLon()))
stopBeans.add(stopBean);
double distance = SphericalGeometryLibrary.distance(center.getLat(),
center.getLon(), stopBean.getLat(), stopBean.getLon());
closest.add(distance, stopBean);
}
boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(stopBeans,
maxCount);