LoginSignup
2
0

More than 3 years have passed since last update.

Yahoo!コンテンツジオコーダAPIを使って施設名から緯度経度を取得する

Posted at

何がしたいか

駅名や施設などのランドマークの名前から緯度と経度を取得したい。

なぜ使うか

ランドマークから緯度や経度を取得できるAPIにはGoogle GeoCoding API があり、無料で利用することができますが、クレジットカードの登録が必要となり簡単に使用することが難しくなりました。
Yahoo の コンテンツジオコーダ API は会員登録が必要なもののクレカの登録は不必要で簡単に利用できます。

使い方

  1. Yahoo! JAPAN ID を取得する。
  2. アプリケーションを登録する。 利用用途に合わせて登録してください。クライアント ID(アプリケーション ID)が発行されます。

主な入力パラメータ

パラメータ 説明
appid(必須) string 先程取得したアプリケーション ID
query(必須) string 検索する文字列
category string(address, landmark, world) ランドマークを検索するときは'landmark'に設定
output string(xml, json) 出力形式

その他のパラメータは公式サイトを参照

curl を利用する場合

curl -v -G -d appid=<YOUR_APP_ID> -d query=東京タワー -d category=landmark https://map.yahooapis.jp/geocode/cont/V1/contentsGeoCoder

axios を利用する場合

axios
  .get("https://map.yahooapis.jp/geocode/cont/V1/contentsGeoCoder", {
    params: {
      appid: YOUR_APP_ID,
      query: "東京タワー",
      category: "landmark",
      output: "json",
    },
  })
  .then((results) => {
    console.log(results);
  });

この方法で緯度経度を取得することができました。
情報の過不足があればコメントお願いします。

2
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
2
0