use of wslite.rest.Response in project axelor-open-suite by axelor.
the class MapService method getMapOsm.
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map<String, Object> getMapOsm(String qString) {
Map<String, Object> result = new HashMap<>();
try {
BigDecimal latitude = BigDecimal.ZERO;
BigDecimal longitude = BigDecimal.ZERO;
RESTClient restClient = new RESTClient("https://nominatim.openstreetmap.org/");
Map<String, Object> mapQuery = new HashMap<>();
mapQuery.put("q", qString);
mapQuery.put("format", "xml");
mapQuery.put("polygon", true);
mapQuery.put("addressdetails", true);
Map<String, Object> mapResponse = new HashMap<>();
mapResponse.put("path", "/search");
mapResponse.put("accept", ContentType.JSON);
mapResponse.put("query", mapQuery);
mapResponse.put("connectTimeout", 10000);
mapResponse.put("readTimeout", 10000);
mapResponse.put("followRedirects", false);
mapResponse.put("useCaches", false);
mapResponse.put("sslTrustAllCerts", true);
Response restResponse = restClient.get(mapResponse);
GPathResult searchresults = new XmlSlurper().parseText(restResponse.getContentAsString());
Iterator<Node> iterator = searchresults.childNodes();
if (iterator.hasNext()) {
Node node = iterator.next();
Map attributes = node.attributes();
if (attributes.containsKey("lat") && attributes.containsKey("lon")) {
if (BigDecimal.ZERO.compareTo(latitude) == 0)
latitude = new BigDecimal(node.attributes().get("lat").toString());
if (BigDecimal.ZERO.compareTo(longitude) == 0)
longitude = new BigDecimal(node.attributes().get("lon").toString());
}
}
LOG.debug("OSMap qString: {}, latitude: {}, longitude: {}", qString, latitude, longitude);
if (BigDecimal.ZERO.compareTo(latitude) != 0 && BigDecimal.ZERO.compareTo(longitude) != 0) {
result.put("url", "map/oneMarker.html?x=" + latitude + "&y=" + longitude + "&z=18");
result.put("latitude", latitude);
result.put("longitude", longitude);
return result;
}
} catch (Exception e) {
TraceBackService.trace(e);
}
return null;
}
use of wslite.rest.Response in project axelor-open-suite by axelor.
the class MapService method testGMapService.
public void testGMapService() throws AxelorException, JSONException {
RESTClient restClient = new RESTClient("https://maps.googleapis.com");
Map<String, Object> responseQuery = new HashMap<>();
responseQuery.put("address", "google");
responseQuery.put("sensor", "false");
responseQuery.put("key", getGoogleMapsApiKey());
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("path", "/maps/api/geocode/json");
responseMap.put("accept", ContentType.JSON);
responseMap.put("query", responseQuery);
responseMap.put("connectTimeout", 5000);
responseMap.put("readTimeout", 10000);
responseMap.put("followRedirects", false);
responseMap.put("useCaches", false);
responseMap.put("sslTrustAllCerts", true);
Response response = restClient.get(responseMap);
getJSON(response);
}
Aggregations