3
1

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 3 years have passed since last update.

Google Maps APIを使用して施設の写真を手にいれる方法

Last updated at Posted at 2021-06-18

概要

GoogleのAPIを使用し、施設の写真を取得する方法を探していた時に、3つのやり方があったのでまとめました。
APIを使用するためにはキーが必要なのですが、以下の記事を参考にして取得しました。
https://qiita.com/Haruka-Ogawa/items/997401a2edcd20e61037

APIを叩く際にはcurlコマンドを使用しました。

方法

Place APIを使用する方法

施設名をパラメーターとして渡し、以下のAPIを叩いて、photo_referenceをレスポンスとして受け取ります。

$ curl -G -d input=〇〇総合体育館 -d inputtype=textquery -d fields=photos -d key=APIキー https://maps.googleapis.com/maps/api/place/findplacefromtext/json

{
   "candidates" : [
      {
         "photos" : [
            {
               "height" : 2448,
               "html_attributions" : [],
               "photo_reference" : "abcdef...",
               "width" : 3264
            }
         ]
      }
   ],
   "status" : "OK"
}

取得したphoto_referenceの値を使用し、以下のAPIを叩き、画像のリンクを取得します。
画像自体はoutput.pngという名前で出力しています。

$ curl -G -d photoreference=abcdef... -d key=APIキー -d maxwidth=400 https://maps.googleapis.com/maps/api/place/photo -L > output.png

Street View Static APIを使用する方法

このAPIを使用するとGoogle Street Viewのパノラマ画像の中から、指定した部分の静止画を取得することができます。fovに視野角、pitchに縦方向の角度、headingに横方向の角度、sizeに画像サイズを指定します。

$ curl -G -d location=〇〇総合体育館 -d fov=100 -d pitch=10 -d heading=0 -d size=600x600 -d key=APIキー https://maps.googleapis.com/maps/api/streetview > output.png

Maps Embed APIを使用する方法

この方法は緯度、経度を指定して、そのストリートビューをWebサイトに埋め込んで使用します。
施設名をパラメーターとして指定できないため、事前に緯度と経度を取得しておく必要があります。

<iframe
  width="450"
  height="250"
  frameborder="0" style="border:0"
  src="https://www.google.com/maps/embed/v1/streetview?key=APIキー&location=46.41...,10.01..." allowfullscreen>
</iframe>
3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?