use of org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult in project onebusaway-application-modules by camsys.
the class SearchServiceImpl method tryAsLatLon.
private void tryAsLatLon(SearchResultCollection results, String rawQuery, SearchResultFactory resultFactory) {
List<SearchResult> routesNearby = null;
Matcher m = latLonPattern.matcher(rawQuery);
if (m.find()) {
String latStr = m.group(1) + m.group(2);
String lonStr = m.group(5) + m.group(6);
_log.info("parse lat/lon = " + latStr + ", " + lonStr);
try {
Double lat = Double.parseDouble(latStr);
Double lon = Double.parseDouble(lonStr);
EnterpriseGeocoderResult egr = new SimpleEnterpriseGeocoderResult(lat, lon);
_log.info("found lat/lon");
results.addMatch(resultFactory.getGeocoderResult(egr, results.getRouteFilter()));
} catch (Exception any) {
_log.info("no results, exception=" + any);
}
}
}
use of org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult in project onebusaway-application-modules by camsys.
the class EnterpriseFilteredGeocoderBase method filterResultsByWktPolygon.
protected List<EnterpriseGeocoderResult> filterResultsByWktPolygon(List<EnterpriseGeocoderResult> input) {
if (_wktFilterPolygon == null) {
return input;
}
List<EnterpriseGeocoderResult> output = new ArrayList<EnterpriseGeocoderResult>();
for (EnterpriseGeocoderResult result : input) {
Coordinate coordinate = new Coordinate(result.getLongitude(), result.getLatitude());
Geometry point = _geometryFactory.createPoint(coordinate);
if (_wktFilterPolygon.intersects(point)) {
output.add(result);
}
}
return output;
}
use of org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult in project onebusaway-application-modules by camsys.
the class EnterpriseBingGeocoderImpl method enterpriseGeocode.
public List<EnterpriseGeocoderResult> enterpriseGeocode(String location, String id, String key) {
try {
List<EnterpriseGeocoderResult> results = new ArrayList<EnterpriseGeocoderResult>();
StringBuilder q = new StringBuilder();
q.append("includeNeighborhood=true");
q.append("&output=xml");
if (location != null && StringUtils.isNotBlank(_regionalSuggestion) && location.indexOf(",") == -1) {
location = location + ", " + _regionalSuggestion;
}
String encodedLocation = URLEncoder.encode(location, "UTF-8");
q.append("&query=").append(encodedLocation);
if (_resultBiasingBounds != null) {
q.append("&userMapView=").append(_resultBiasingBounds.getMinLat() + "," + _resultBiasingBounds.getMinLon() + "," + _resultBiasingBounds.getMaxLat() + "," + _resultBiasingBounds.getMaxLon());
}
String secretKey = key;
if (secretKey != null && !StringUtils.isEmpty(secretKey)) {
q.append("&key=").append(secretKey);
}
URL url = new URL(GEOCODE_URL_PREFIX + "?" + q.toString());
Digester digester = createDigester();
digester.push(results);
_log.debug("Requesting " + url.toString());
InputStream inputStream = url.openStream();
digester.parse(inputStream);
_log.debug("Got " + results.size() + " geocoder results.");
results = filterResultsByWktPolygon(results);
_log.debug("Have " + results.size() + " geocoder results AFTER filtering.");
return results;
} catch (Exception e) {
_log.error("Geocoding error: " + e.getMessage());
return null;
}
}
use of org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult in project onebusaway-application-modules by camsys.
the class EnterpriseGoogleGeocoderImpl method enterpriseGeocode.
public List<EnterpriseGeocoderResult> enterpriseGeocode(String location) {
try {
List<EnterpriseGeocoderResult> results = new ArrayList<EnterpriseGeocoderResult>();
StringBuilder q = new StringBuilder();
q.append("sensor=").append(_sensor);
String encodedLocation = URLEncoder.encode(location, "UTF-8");
q.append("&address=").append(encodedLocation);
if (_resultBiasingBounds != null) {
q.append("&bounds=").append(_resultBiasingBounds.getMinLat() + "," + _resultBiasingBounds.getMinLon() + "|" + _resultBiasingBounds.getMaxLat() + "," + _resultBiasingBounds.getMaxLon());
}
String clientId = _configurationService.getConfigurationValueAsString("display.googleMapsClientId", null);
String authKey = _configurationService.getConfigurationValueAsString("display.googleMapsSecretKey", null);
String channelId = _configurationService.getConfigurationValueAsString("display.googleMapsChannelId", null);
// Fail if we don't have client key, auth key, channel id
if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(authKey) || StringUtils.isEmpty(channelId)) {
_log.warn("No clientId, authKey, or channelId. Not accessing Google.");
return Collections.emptyList();
}
q.append("&client=").append(clientId);
q.append("&channel=").append(channelId);
URL url = new URL(GEOCODE_URL_PREFIX + signRequest(authKey, GEOCODE_PATH + "?" + q.toString()));
Digester digester = createDigester();
digester.push(results);
_log.debug("Requesting " + url.toString());
InputStream inputStream = url.openStream();
digester.parse(inputStream);
_log.debug("Got " + results.size() + " geocoder results.");
results = filterResultsByWktPolygon(results);
_log.debug("Have " + results.size() + " geocoder results AFTER filtering.");
return results;
} catch (Exception e) {
_log.error("Geocoding error: " + e.getMessage());
return null;
}
}
Aggregations