コード例 #1
0
ファイル: Nominatim.java プロジェクト: agustinf/OpenGTS
 private String getAddressReverseGeocodeURL(GeoPoint gp) {
   //  -
   // http://nominatim.openstreetmap.org/reverse?format=xml&addressdetails=1&zoom=18&lat=46.17330&lon=21.29370
   StringBuffer sb = new StringBuffer();
   RTProperties rtp = this.getProperties();
   String url = rtp.getString(PROP_reverseURL, null);
   if (!StringTools.isBlank(url)) {
     sb.append(url);
   } else {
     String host = rtp.getString(PROP_hostName, HOST_PRIMARY);
     sb.append("http://");
     sb.append(host);
     if (host.indexOf("mapquest") >= 0) {
       sb.append("/nominatim/v1/reverse?");
     } else {
       sb.append("/reverse?");
     }
   }
   sb.append("format=xml&");
   sb.append("limit=1&");
   // sb.append("osm_type=W&");
   sb.append("addressdetails=").append(rtp.getString(PROP_addressdetails, "1")).append("&"); // 0,1
   sb.append("zoom=").append(rtp.getString(PROP_zoom, "18")).append("&"); // 0..18
   sb.append("email=").append(this.getEmail()).append("&"); // required, per usage policy
   sb.append("lat=").append(gp.getLatitudeString(GeoPoint.SFORMAT_DEC_5, null)).append("&");
   sb.append("lon=").append(gp.getLongitudeString(GeoPoint.SFORMAT_DEC_5, null));
   return sb.toString();
 }
コード例 #2
0
  /* encode GeoPoint into nearest address URI */
  protected String getAddressReverseGeocodeURL(GeoPoint gp, String localStr) {
    StringBuffer sb = new StringBuffer();
    GoogleSig sig = this.getSignature();

    /* predefined URL */
    String rgURL = this.getProperties().getString(PROP_reverseGeocodeURL, null);
    if (!StringTools.isBlank(rgURL)) {
      sb.append(rgURL);
      sb.append("&ll=")
          .append(gp.getLatitudeString(GeoPoint.SFORMAT_DEC_5, null))
          .append(",")
          .append(gp.getLongitudeString(GeoPoint.SFORMAT_DEC_5, null));
      String defURL = sb.toString();
      if (sig == null) {
        return defURL;
      } else {
        String urlStr = sig.signURL(defURL);
        return (urlStr != null) ? urlStr : defURL;
      }
    }

    /* assemble URL */
    sb.append(this.getAddressReverseGeocodeURI());
    sb.append("output=xml");
    sb.append("&oe=utf8");

    /* latitude/longitude */
    sb.append("&ll=")
        .append(gp.getLatitudeString(GeoPoint.SFORMAT_DEC_5, null))
        .append(",")
        .append(gp.getLongitudeString(GeoPoint.SFORMAT_DEC_5, null));

    /* sensor */
    String sensor = this.getProperties().getString(PROP_sensor, null);
    if (!StringTools.isBlank(sensor)) {
      sb.append("&sensor=").append(sensor);
    }

    /* key */
    String channel = this.getProperties().getString(PROP_channel, null);
    String auth = this.getAuthorization();
    if (StringTools.isBlank(auth) || auth.startsWith("*")) {
      // invalid key
    } else if (auth.startsWith(CLIENT_ID_PREFIX)) {
      sb.append("&client=").append(auth);
      if (StringTools.isBlank(channel)) {
        channel = DBConfig.getServiceAccountID(null);
      }
    } else {
      sb.append("&key=").append(auth);
    }

    /* channel */
    if (!StringTools.isBlank(channel)) {
      sb.append("&channel=").append(channel);
    }

    /* localization ("&hl=") */
    if (!StringTools.isBlank(localStr)) {
      sb.append("&hl=").append(localStr);
    }

    /* return url */
    String defURL = sb.toString();
    if (sig == null) {
      return defURL;
    } else {
      String urlStr = sig.signURL(defURL);
      return (urlStr != null) ? urlStr : defURL;
    }
  }