Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>addr cleansing sample</title>
</head>

<body>
  <h3>住所入力</h3>
  <p>
    <input id="anormInput" placeholder="住所を入力してください" value="東京都文京区本駒込2丁目28-10 文京グリーンコート" type="text">
    <button id="submitButton">ジオコーディング実行</button>
  </p>
  <hr>
  <h3>ジオコーディング結果</h3>
  <p>APIレスポンスコード:<span id="status"></span><br>
    <span id="errorMessage"></span>
  </p>
  <p>
  <table border="1">
    <tr>
      <th>フィールド名</th>
      <th>ジオコーディング結果</th>
    </tr>
    <tr>
      <td>経度,緯度</td>
      <td id="coordinates"></td>
    </tr>
  </table>
  </p>

  <h3>正規化結果</h3>
  <table border="1">
    <tr>
      <th>フィールド名</th>
      <th>正規化結果</th>
    </tr>
    <tr>
      <td>入力住所文字列</td>
      <td id="query"></td>
    </tr>
    <tr>
      <td>正規化後の住所文字列</td>
      <td id="placeName"></td>
    </tr>
    <tr>
      <td>都道府県名</td>
      <td id="pref"></td>
    </tr>
    <tr>
      <td>都道府県読み</td>
      <td id="prefKana"></td>
    </tr>
    <tr>
      <td>市区町村名</td>
      <td id="city"></td>
    </tr>
    <tr>
      <td>市区町村読み</td>
      <td id="cityKana"></td>
    </tr>
    <tr>
      <td>町域名</td>
      <td id="area"></td>
    </tr>
    <tr>
      <td>町域名読み</td>
      <td id="areaKana"></td>
    </tr>
    <tr>
      <td>小字・丁目</td>
      <td id="koazaChome"></td>
    </tr>
    <tr>
      <td>小字・丁目読み</td>
      <td id="koazaChomeKana"></td>
    </tr>
    <tr>
      <td>番地・号</td>
      <td id="banchiGo"></td>
    </tr>
    <tr>
      <td>建物名称部</td>
      <td id="building"></td>
    </tr>
    <tr>
      <td>建物数字部</td>
      <td id="buildingNumber"></td>
    </tr>
    <tr>
      <td>郵便番号</td>
      <td id="zipcode"></td>
    </tr>
    <tr>
      <td>解析レベル</td>
      <td id="geocodingLevel"></td>
    </tr>
    <tr>
      <td>解析レベル説明</td>
      <td id="geocodingLevelDesc"></td>
    </tr>
    <tr>
      <td>解析ログメッセージ</td>
      <td id="log"></td>
    </tr>
    <tr>
      <td>正規化できなかった文字列</td>
      <td id="notNormalized"></td>
    </tr>
  </table>

  <footer>GeoTechnologies Addr Geocoding API Sample Code</footer>

</body>

</html>
              
            
!

CSS

              
                body {
  text-align: center;
}

table {
  border-collapse: collapse;
  margin: auto;
  text-align: left;
}

#errorMessage {
  font-size: 12px;
  color: red;
}

#anormInput {
  width: 75%;
  max-width: 450px;
}

              
            
!

JS

              
                /**
 * ボタン押下時にジオコーディングを実行します
 */
document.getElementById("submitButton").onclick = function () {
  // ジオコーディングAPIにリクエストを送信します
  fetch(makeURI(), {
    // YourApiKey部分をお客様のAPIキーに修正してください
    // 例 "x-api-key": "6QHCWbbsnQ1K08IcwP",
    headers: { "x-api-key": "YourApiKey", accept: "application/json" }
  })
    .then((response) => {
      // ジオコーディングAPIのレスポンスコードを解析します
      analyzeResponseCode(response.status);
      return response.json();
    })
    .then((result) => {
      // 住所正規化結果を解析して表示します
      getNormalized(result);
    })
    .catch((error) => {
      // エラー時の処理を記載します
      // alert(error);
    });
};

/**
 * ジオコーディングAPI用のURIを作成します
 * @return {string} ジオコーディングAPI用のURI
 */
function makeURI() {
  const urlValue =
    "https://api-anorm.mapfan.com/v1/" +
    document.getElementById("anormInput").value +
    // ジオコーディングが不要な場合は「.json」を使用してください
    ".geojson";
  return encodeURI(urlValue);
}

/**
 * ジオコーディングAPIのレスポンスコードを解析し、表示・エラー出力を行います
 * @param {string} responseCode ジオコーディングAPIのレスポンスコード
 */
function analyzeResponseCode(responseCode) {
  document.getElementById("status").innerHTML = responseCode;

  // 200以外のレスポンスコードはエラーです
  if (responseCode == "200")
    document.getElementById("errorMessage").innerHTML = "";
  else if (responseCode == "400")
    document.getElementById("errorMessage").innerHTML =
      "住所入力が行われているか確認してください";
  else if (responseCode == "403")
    document.getElementById("errorMessage").innerHTML =
      "JavaScriptのAPIキーが正しいか確認してください";
  else
    document.getElementById("errorMessage").innerHTML =
      "システムエラーが発生しました";
}

/**
 * 住所正規化結果を解析し表示します
 * @param {json} result ジオコーディングAPIの住所正規化結果
 */
function getNormalized(result) {
  // 一件目の住所正規化結果を取得します
  // 複数件リクエストした場合は複数件取得する処理に変更します
  const feature = result.features[0];

  // 経度,緯度
  if (feature.geometry != null) {
    document.getElementById("coordinates").innerHTML =
      feature.geometry.coordinates;
  }

  // 入力住所文字列
  document.getElementById("query").innerHTML = feature.properties.query;
  // 正規化後の住所文字列
  document.getElementById("placeName").innerHTML =
    feature.properties.place_name;
  // 都道府県名
  document.getElementById("pref").innerHTML = feature.properties.pref;
  // 都道府県読み
  document.getElementById("prefKana").innerHTML = feature.properties.pref_kana;
  // 市区町村名
  document.getElementById("city").innerHTML = feature.properties.city;
  // 市区町村読み
  document.getElementById("cityKana").innerHTML = feature.properties.city_kana;
  // 町域名
  document.getElementById("area").innerHTML = feature.properties.area;
  // 町域名読み
  document.getElementById("areaKana").innerHTML = feature.properties.area_kana;
  // 小字・丁目
  document.getElementById("koazaChome").innerHTML =
    feature.properties.koaza_chome;
  // 小字・丁目読み
  document.getElementById("koazaChomeKana").innerHTML =
    feature.properties.koaza_chome_kana;
  // 番地・号
  document.getElementById("banchiGo").innerHTML = feature.properties.banchi_go;
  // 建物名称部
  document.getElementById("building").innerHTML = feature.properties.building;
  // 建物数字部
  document.getElementById("buildingNumber").innerHTML =
    feature.properties.building_number;
  // 郵便番号
  document.getElementById("zipcode").innerHTML = feature.properties.zipcode;
  // 解析レベル
  document.getElementById("geocodingLevel").innerHTML =
    feature.properties.geocoding_level;
  // 解析レベル説明
  document.getElementById("geocodingLevelDesc").innerHTML =
    feature.properties.geocoding_level_desc;
  // 解析ログメッセージ
  document.getElementById("log").innerHTML = feature.properties.log;
  // 正規化できなかった文字列
  document.getElementById("notNormalized").innerHTML =
    feature.properties.not_normalized;
}

              
            
!
999px

Console