Google Maps Platformの Maps Static APIによる地図画像の取得方法をご紹介します。
Maps Static APIは Googleが提供する Google Maps Platformの RESTサービスです。指定された URLにアクセスすると地図画像を返します。
APIキーの取得
APIキーが必要です。APIキーの取得方法は APIキーの作成を参照してください。
APIの有効化
Maps Static APIを有効化する必要があります。
Google Cloud Platformにログインし、Google Cloud Platform 画面左上のナビゲーションメニューから「APIとサービス」、「ライブラリ」を選択します。
![](https://sizukana.net/wp-content/uploads/google_start0.png)
検索ボックスで”Maps Static API”を入力して検索します。
![](https://sizukana.net/wp-content/uploads/google_api_enable1.jpg)
「Maps Static API」を選択します。
![](https://sizukana.net/wp-content/uploads/google_api_enable2.jpg)
「有効にする」を選択します。これで Maps Static APIが使用可能になります。
![](https://sizukana.net/wp-content/uploads/google_api_enable3.jpg)
APIのパラメータ
https://maps.googleapis.com/maps/api/staticmap?center={center}&format={format}&maptype={maptype}&key={key}&size={size}&zoom={zoom}
パラメータの内容は以下のとおりです。
center | 地図の中心位置(”緯度,軽度”) |
format | 地図画像のフォーマット(gif、jpeg、png) デフォルトはpng |
maptype | 地図の種類 satellite(航空写真)、roadmap(ロードイメージ)など |
key | APIキー |
size | 地図画像のサイズ(”横幅x縦幅”) |
zoom | ズームレベル(0~21) |
パラメータの詳細についてはURL Parametersを参照してください。
実行サンプル
以下をブラウザの URL欄に入力して実行すると地図画像が表示されます。
※ APIキーを記述してください。
https://maps.googleapis.com/maps/api/staticmap?zoom=19&maptype=satellite¢er=35.68135257803937,139.76609230041504&size=400x300&key=APIキー
![](https://sizukana.net/wp-content/uploads/google_satellite_zoom19.png)
https://maps.googleapis.com/maps/api/staticmap?zoom=16&maptype=roadmap¢er=35.68135257803937,139.76609230041504&size=400x300&key=APIキー
![](https://sizukana.net/wp-content/uploads/google_roadmap_zoom16.png)
HTMLファイルのソースコードです。ブラウザで実行すると地図画像が表示されます。
※ APIキーを記述してください。
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
</head>
<body>
<div><img src="https://maps.googleapis.com/maps/api/staticmap?zoom=19&maptype=satellite¢er=35.68135257803937,139.76609230041504&format=GIF&size=640x400&key=APIキー" style="width:640px; height:400px;">
</body>
</html>
コメント