protected GeolocDao geolocDao;
// GEOLOC CITY
public GeolocCity geolocByCityAndCountry(final String city, final String country){
GeolocCity geolocCity = null;
String address = city.replace(" ", "+") + "," + country.replace(" ", "+");
String key = null;
try {
key = engineSettingService.getGoogleGeolocationApiKey();
} catch (Exception e) {
logger.error("Google Geolocation API Key is mandatory!", e);
}
if(key != null && StringUtils.isNotEmpty(key)){
HttpPost request = new HttpPost("https://maps.googleapis.com/maps/api/geocode/json?address=" + address + "&key=" + key);
HttpResponse response = null;
HttpClient httpClient = new DefaultHttpClient();
try {
response = httpClient.execute(request);
} catch (ClientProtocolException e) {
logger.error("", e);
} catch (IOException e) {
logger.error("", e);
}
try {
BufferedReader streamReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null){
responseStrBuilder.append(inputStr);
}
String json = responseStrBuilder.toString();
ObjectMapper mapper = new ObjectMapper();
GoogleGeoCode geoCode = mapper.readValue(json, GoogleGeoCode.class);
geolocCity = new GeolocCity();
geolocCity.setCity(city);
geolocCity.setCountry(country);
geolocCity.setJson(json);
geolocCity.setLatitude(geoCode.getLatitude());
geolocCity.setLongitude(geoCode.getLongitude());
geolocCity = geolocDao.saveOrUpdateGeolocCity(geolocCity);
} catch (IllegalStateException e) {
logger.error("", e);
} catch (IOException e) {