예제 #1
0
  public GeolocAddress geolocByLatitudeLongitude(final String latitude, final String longitude) {
    GeolocAddress geolocAddress = null;
    GoogleGeoCode geoCode = geolocGoogleWithLatitudeLongitude(latitude, longitude);
    if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) {
      logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage());
      engineSettingService.flagSettingGoogleGeolocationApiOverQuota();
      return geolocAddress;
    }

    if (geoCode != null && geoCode.getResults().size() > 0) {
      GoogleGeoCodeResult googleGeoCodeResult = geoCode.getResults().get(0);
      String formatedAdress = googleGeoCodeResult.getFormattedAddress();
      formatedAdress = formatedAdress.replace(" ", "+").replace("\"", "+");

      geolocAddress = new GeolocAddress();
      geolocAddress.setAddress(googleGeoCodeResult.getAddress());
      geolocAddress.setPostalCode(googleGeoCodeResult.getPostalCode());
      geolocAddress.setCity(googleGeoCodeResult.getCity());
      geolocAddress.setCountry(googleGeoCodeResult.getCountryCode());
      geolocAddress.setJson(SerializationHelper.serialize(geoCode));
      geolocAddress.setFormatedAddress(formatedAdress);
      geolocAddress.setLatitude(latitude);
      geolocAddress.setLongitude(longitude);

      // SANITY CHECK : DON'T SAVE AN ADDRESS WHICH ALREADY EXIST BUT WAS LOCATED WITH LAT/LONG
      // DIFFERENT
      GeolocAddress geolocGeolocAddress =
          geolocDao.getGeolocAddressByFormatedAddress(formatedAdress);
      if (geolocGeolocAddress == null) {
        geolocAddress = geolocDao.saveOrUpdateGeolocAddress(geolocAddress);
      }
    }
    return geolocAddress;
  }
예제 #2
0
 public GeolocAddress getGeolocAddressByFormatedAddress(
     final String formatedAddress, Object... params) {
   return geolocDao.getGeolocAddressByFormatedAddress(formatedAddress, params);
 }