Example #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;
  }
Example #2
0
  public GeolocAddress geolocByAddress(
      final String address, final String postalCode, final String city, final String country) {
    GeolocAddress geolocAddress = null;
    String formatedAddress = encodeGoogleAddress(address, postalCode, city, country);
    GoogleGeoCode geoCode = geolocGoogleWithAddress(formatedAddress);
    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) {
      geolocAddress = new GeolocAddress();
      geolocAddress.setAddress(address);
      geolocAddress.setPostalCode(postalCode);
      geolocAddress.setCity(city);
      geolocAddress.setCountry(country);
      geolocAddress.setJson(SerializationHelper.serialize(geoCode));
      geolocAddress.setFormatedAddress(formatedAddress);
      geolocAddress.setLatitude(geoCode.getLatitude());
      geolocAddress.setLongitude(geoCode.getLongitude());
      geolocAddress = geolocDao.saveOrUpdateGeolocAddress(geolocAddress);
    }
    return geolocAddress;
  }