1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

what3words APIの基本的な機能の紹介

Posted at

what3wordsのAPIを使ってみる

APIキーを取得したら、実際にAPIを使ってみましょう。

キーの発行は、こちらから確認できます。

① what3words→緯度経度への変換
what3wordsアドレスを緯度経度に変換します(フォワードジオコーディング)


https://api.what3words.com/v3/convert-to-coordinates?words=ふなで。めいかく。にんたい&key=[API-KEY]

下記JSONリクエスト結果



{
  "country": "JP",
  "square": {
    "southwest": {
      "lng": 139.745422,
      "lat": 35.658581
    },
    "northeast": {
      "lng": 139.745455,
      "lat": 35.658608
    }
  },
  "nearestPlace": "東京都",
  "coordinates": {
    "lng": 139.745439,
    "lat": 35.658595
  },
  "words": "ふなで。めいかく。にんたい",
  "language": "ja",
  "map": "https://w3w.co/%E3%81%B5%E3%81%AA%E3%81%A7%E3%80%82%E3%82%81%E3%81%84%E3%81%8B%E3%81%8F%E3%80%82%E3%81%AB%E3%82%93%E3%81%9F%E3%81%84"
}

///ふなで。めいかく。にんたい は東京タワーにあるエレベーター乗り場の一つです。

② 緯度経度→what3wordsへの変換
任意の場所の緯度経度をwhat3wordsに変換します(リバースジオコーディング)


https://api.what3words.com/v3/convert-to-3wa?coordinates=51.521251,-0.203586&key=[API-KEY]

下記JSONリクエスト結果



{
  "country": "JP",
  "square": {
    "southwest": {
      "lng": 139.745422,
      "lat": 35.658581
    },
    "northeast": {
      "lng": 139.745455,
      "lat": 35.658608
    }
  },
  "nearestPlace": "東京都",
  "coordinates": {
    "lng": 139.745439,
    "lat": 35.658595
  },
  "words": "ふなで。めいかく。にんたい",
  "language": "ja",
  "map": "https://w3w.co/%E3%81%B5%E3%81%AA%E3%81%A7%E3%80%82%E3%82%81%E3%81%84%E3%81%8B%E3%81%8F%E3%80%82%E3%81%AB%E3%82%93%E3%81%9F%E3%81%84"
}

③ サジェスト機能
入力の間違えの可能性を踏まえ、検索結果に3つの似た組み合わせ出します


https://api.what3words.com/v3/autosuggest?input=ふなで。めいかく。にんたい&key=[API-KEY]

下記JSONリクエスト結果



{
  "suggestions":[
    {
        "country":"JP",
        "nearestPlace":"東京都",
        "words":"ふなで。めいかく。にんたい",
        "rank":1,
        "language":"ja"
    },
    {
        "country":"CH",
        "nearestPlace":"Mörschwil, Saint Gallen",
        "words":"ふなで。めいかく。にんてい",
        "rank":2,
        "language":"ja"
    },
    {
        "country":"CN",
        "nearestPlace":"Zhoucheng, 山東省",
        "words":"なふだ。めいかく。にんたい",
        "rank":3,
        "language":"ja"
    }
 ]
}

候補結果を日本国内または特定のエリアのみにクリップする事もできます

④ グリッド機能
表示されているマップUIにマス目を表示します


curl --request GET
--url 'https://api.what3words.com/v3/grid-section?key=[API-KEY]&bounding-box=52.207988%2C0.116126%2C52.208867%2C0.117540&format=json'

下記JSONリクエスト結果



{
  "lines": [
      {
          "start": {
              "lng": 0.116126,
              "lat": 52.208009918068136
          },
          "end": {
              "lng": 0.11754,
              "lat": 52.208009918068136
          }
      },
      {
          "start": {
              "lng": 0.116126,
              "lat": 52.20803686934023
          },
          "end": {
              "lng": 0.11754,
              "lat": 52.20803686934023
          }
      }
  ]
}

留意事項
① HTTPS GETメソッドのみ
② リクエストURLにAPIキーを入れるkey=api-key
③ CORS対応

次回はJava、iOSやAndroidでの内容を紹介したいと思います!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?