Class StaticMap

StaticMap

静的な地図画像の作成と装飾を可能にします。

以下の例は、このクラスを使用して、近くの駅を含むニューヨーク市のシアター ディストリクトの地図を作成し、シンプルなウェブアプリに表示する方法を示しています。

// Create a map centered on Times Square.
var map = Maps.newStaticMap()
    .setSize(600, 600)
    .setCenter('Times Square, New York, NY');

// Add markers for the nearbye train stations.
map.setMarkerStyle(Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.RED, 'T');
map.addMarker('Grand Central Station, New York, NY');
map.addMarker('Penn Station, New York, NY');

// Show the boundaries of the Theatre District.
var corners = [
  '8th Ave & 53rd St, New York, NY',
  '6th Ave & 53rd St, New York, NY',
  '6th Ave & 40th St, New York, NY',
  '8th Ave & 40th St, New York, NY'
];
map.setPathStyle(4, Maps.StaticMap.Color.BLACK, Maps.StaticMap.Color.BLUE);
map.beginPath();
for (var i = 0; i < corners.length; i++) {
  map.addAddress(corners[i]);
}
// All static map URLs require an API key.
var url = map.getMapUrl() + "&key=YOUR_API_KEY";

関連ドキュメント

  • Google Static Maps API

Methods

メソッド戻り値の型概要
addAddress(address)StaticMap現在のパス定義に新しいアドレスを追加します。
addMarker(latitude, longitude)StaticMap地点(緯度/経度)を使用して、地図にマーカーを追加します。
addMarker(address)StaticMap住所を使用して、地図にマーカーを追加します。
addPath(points)StaticMapポイントの配列を使用して、地図にパスを追加します。
addPath(polyline)StaticMapエンコードされたポリラインを使用して、地図にパスを追加します。
addPoint(latitude, longitude)StaticMap現在の経路の定義に新しい地点(緯度/経度)を追加します。
addVisible(latitude, longitude)StaticMap地図上に表示する必要のある地点(緯度/経度)を追加します。
addVisible(address)StaticMap地図に表示する必要のある住所の場所を追加します。
beginPath()StaticMap新しいパス定義を開始します。
clearMarkers()StaticMap現在のマーカーのセットをクリアします。
clearPaths()StaticMap現在の経路セットを消去します。
clearVisibles()StaticMap現在表示されている場所のセットをクリアします。
endPath()StaticMapstartPath() で始まるパス定義を完了します。
getAs(contentType)Blobこのオブジェクト内のデータを、指定されたコンテンツ タイプに変換された blob として返します。
getBlob()Blob画像データを Blob として取得します。
getMapImage()Byte[]未加工の画像データをバイト配列として取得します。
getMapUrl()String地図画像の URL を取得します。
setCenter(latitude, longitude)StaticMap地点(緯度/経度)を使用して地図の中心を設定します。
setCenter(address)StaticMap住所を使用して地図の中心を設定します。
setCustomMarkerStyle(imageUrl, useShadow)StaticMap新しいマーカーの作成時に使用するカスタム マーカー画像を設定します。
setFormat(format)StaticMap地図画像の形式を設定します。
setLanguage(language)StaticMap地図上のテキストに使用する言語を設定します(ただし、avaialbe が対象)。
setMapType(mapType)StaticMap表示する地図のタイプを設定します。
setMarkerStyle(size, color, label)StaticMap新しいマーカーの作成時に使用するマーカー スタイルを設定します。
setMobile(useMobileTiles)StaticMapモバイル デバイス専用のタイルセットを使用するかどうかを設定します。
setPathStyle(weight, color, fillColor)StaticMap新しいパスの作成時に使用するパスのスタイルを設定します。
setSize(width, height)StaticMap地図画像の幅と高さをピクセル単位で設定します。
setZoom(zoom)StaticMap地図で使用されるズーム倍率(拡大レベル)を設定します。

詳細なドキュメント

addAddress(address)

現在のパス定義に新しいアドレスを追加します。

// Creates a map and adds a path from New York to Boston.
var map = Maps.newStaticMap()
    .beginPath()
    .addAddress('New York, NY')
    .addAddress('Boston, MA')
    .endPath();

パラメータ

名前説明
addressString追加する住所。

リターン

StaticMap - チェーン用のこのマップ インスタンス。


addMarker(latitude, longitude)

地点(緯度/経度)を使用して、地図にマーカーを追加します。

// Creates a map and adds a marker at the specified coordinates.
var map = Maps.newStaticMap().addMarker(40.741799, -74.004207);

パラメータ

名前説明
latitudeNumber新しいマーカーの緯度。
longitudeNumber新しいマーカーの経度。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

addMarker(address)

住所を使用して、地図にマーカーを追加します。

// Creates a map and adds a marker at the specified address.
var map = Maps.newStaticMap().addMarker('76 9th Ave, New York NY');

パラメータ

名前説明
addressString新しいマーカーを配置する住所です。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

addPath(points)

ポイントの配列を使用して、地図にパスを追加します。

// Creates a map and adds a path from New York to Boston.
var map = Maps.newStaticMap()
    .addPath([40.714353, -74.005973, 42.358431, -71.059773]);

パラメータ

名前説明
pointsNumber[]経路を定義する緯度と経度のペアの配列。

リターン

StaticMap - チェーン用のこのマップ インスタンス。


addPath(polyline)

エンコードされたポリラインを使用して、地図にパスを追加します。

// Creates a map and adds a path from New York to Boston.
var polyline = Maps.encodePolyline([40.714353, -74.005973, 42.358431, -71.059773]);
var map = Maps.newStaticMap().addPath(polyline);

パラメータ

名前説明
polylineStringエンコードされたポリライン。

リターン

StaticMap - チェーン用のこのマップ インスタンス。


addPoint(latitude, longitude)

現在の経路の定義に新しい地点(緯度/経度)を追加します。

// Creates a map and adds a path from New York to Boston.
var map = Maps.newStaticMap()
    .beginPath()
    .addPoint(40.714353, -74.005973)
    .addPoint(42.358431, -71.059773)
    .endPath();

パラメータ

名前説明
latitudeNumberポイントの緯度。
longitudeNumber地点の経度。

リターン

StaticMap - チェーン用のこのマップ インスタンス。


addVisible(latitude, longitude)

地図に表示する必要のある地点(緯度/経度)を追加します。

// Creates a map where New York and Boston are visible.
var map = Maps.newStaticMap()
    .addVisible(40.714353, -74.005973);
    .addVisible(42.358431, -71.059773)

パラメータ

名前説明
latitudeNumberポイントの緯度。
longitudeNumber地点の経度。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

addVisible(address)

地図に表示する必要のある住所の場所を追加します。

// Creates a map where New York and Boston are visible.
var map = Maps.newStaticMap()
    .addVisible('New York, NY')
    .addVisible('Boston, MA');

パラメータ

名前説明
addressString地図に表示する必要がある住所。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

beginPath()

新しいパス定義を開始します。addAddress()addPoint() の呼び出しにより、パス内の新しい頂点が定義されます。endPath() が呼び出されると、パスは完成します。

// Creates a map and adds a path from New York to Boston.
var map = Maps.newStaticMap()
    .beginPath()
    .addAddress('New York, NY')
    .addAddress('Boston, MA')
    .endPath();

リターン

StaticMap - チェーン用のこのマップ インスタンス。


clearMarkers()

現在のマーカーのセットをクリアします。

var map = Maps.newStaticMap();
// ...
// Do something interesting here ...
// ...
// Remove all markers on the map.
map.clearMarkers();

リターン

StaticMap - チェーン用のこのマップ インスタンス。


clearPaths()

現在のパスセットをクリアします。

var map = Maps.newStaticMap();
// ...
// Do something interesting here ...
// ...
// Remove all paths on the map.
map.clearPaths();

リターン

StaticMap - チェーン用のこのマップ インスタンス。


clearVisibles()

現在表示されている場所のセットをクリアします。

var map = Maps.newStaticMap();
// ...
// Do something interesting here ...
// ...
// Remove all visible locations created with addVisible().
map.clearVisibles();

リターン

StaticMap - チェーン用のこのマップ インスタンス。


endPath()

startPath() で始まるパス定義を完了します。

// Creates a map and adds a path from New York to Boston.
var map = Maps.newStaticMap()
    .beginPath()
    .addAddress('New York, NY')
    .addAddress('Boston, MA')
    .endPath();

リターン

StaticMap - チェーン用のこのマップ インスタンス。


getAs(contentType)

このオブジェクト内のデータを、指定されたコンテンツ タイプに変換された blob として返します。この方法では、ファイル名に適切な拡張子(「myfile.pdf」など)が追加されます。ただし、ファイル名の最後のピリオド(存在する場合)に続く部分は、置き換えられる既存の拡張子であることを前提としています。この結果、「ShoppingList.12.25.2014」は「ShoppingList.12.25.pdf」になります。

コンバージョンの 1 日あたりの割り当てを確認するには、Google サービスの割り当てをご覧ください。新しく作成された Google Workspace ドメインには、一時的に割り当てが厳しくなることがあります。

パラメータ

名前説明
contentTypeString変換先の MIME タイプ。ほとんどの blob では、有効なオプションは 'application/pdf' のみです。BMP、GIF、JPEG、PNG 形式の画像の場合は、'image/bmp''image/gif''image/jpeg''image/png' のいずれかも有効です。

リターン

Blob - blob としてのデータ。


getBlob()

画像データを Blob として取得します。

// Creates a map centered on Times Square and saves it to Google Drive.
var map = Maps.newStaticMap().setCenter('Times Square, New York, NY');
DocsList.createFile(map);  // You can call map.getBlob() explicitly or use it
                           // implicitly by passing the map where a blob is expected.

リターン

Blob - 選択した画像形式の地図の画像。


getMapImage()

未加工の画像データをバイト配列として取得します。

通常は、他のサービスとのやり取りを簡素化できる getBlob() を使用することをおすすめします。

// Creates a map centered on Times Square and saves it to Google Drive.
var map = Maps.newStaticMap().setCenter('Times Square, New York, NY');
DocsList.createFile(Utilities.newBlob(map.getMapImage(), 'image/png', 'map.png'));

リターン

Byte[] - 選択した画像形式の地図の画像。


getMapUrl()

地図画像の URL を取得します。

// Creates a map centered on Times Square and gets the URL.
var map = Maps.newStaticMap().setCenter('Times Square, New York, NY');
// All static map URLs require an API key.
Logger.log(map.getMapUrl() + "&key=YOUR_API_KEY");

リターン

String - URL。マップ画像の URL。


setCenter(latitude, longitude)

地点(緯度/経度)を使用して地図の中心を設定します。

// Creates a map centered on Times Square, using its coordinates.
var map = Maps.newStaticMap().setCenter(40.759011, -73.984472);

パラメータ

名前説明
latitudeNumber中心の緯度。
longitudeNumber中心の経度。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

setCenter(address)

住所を使用して地図の中心を設定します。

// Creates a map centered on Times Square, using its address.
var map = Maps.newStaticMap().setCenter('Times Square, New York, NY');

パラメータ

名前説明
addressStringセンターの住所。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

setCustomMarkerStyle(imageUrl, useShadow)

新しいマーカーの作成時に使用するカスタム マーカー画像を設定します。すでに追加されているマーカーには影響しません。

// Creates a map with markers set to be medium sized, black, and labeled with the number "1".
var map = Maps.newStaticMap()
    .setCustomMarkerStyle('http://www.example.com/marker.png', false);

パラメータ

名前説明
imageUrlStringマーカーのカスタム アイコンとして使用する URL を指定します。画像は PNG、JPEG、GIF の形式を使用できますが、PNG が推奨されます。
useShadowBoolean画像の表示領域と不透明度/透明度に基づいて、マーカーに影が生成されることを示します。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

setFormat(format)

地図画像の形式を設定します。

// Creates a map with the image format set to PNG.
var map = Maps.newStaticMap().setFormat(Maps.StaticMap.Format.PNG);

パラメータ

名前説明
formatStringFormat の定数値。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

setLanguage(language)

地図上のテキスト(avaialbe)に使用する言語を設定します。

// Creates a map with the language set to French.
var map = Maps.newStaticMap().setLanguage('fr');

パラメータ

名前説明
languageStringBCP-47 言語識別子。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント


setMapType(mapType)

表示する地図のタイプを設定します。

// Creates a satellite map.
var map = Maps.newStaticMap().setMapType(Maps.StaticMap.Type.SATELLITE);

パラメータ

名前説明
mapTypeStringType の定数値。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

setMarkerStyle(size, color, label)

新しいマーカーの作成時に使用するマーカー スタイルを設定します。すでに追加されているマーカーには影響しません。

// Creates a map with markers set to be medium sized, black, and labeled with the number "1".
var map = Maps.newStaticMap()
    .setMarkerStyle(Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.BLACK , '1');

パラメータ

名前説明
sizeStringMarkerSize の定数値。
colorString「0xrrggbb」形式の文字列または Color の定数値。
labelStringA ~ Z または 0 ~ 9 の 1 つの文字を含む文字列。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

setMobile(useMobileTiles)

モバイル デバイス専用のタイルセットを使用するかどうかを設定します。

// Creates a map that uses mobile-friendly tiles.
var map = Maps.newStaticMap().setMobile(true);

パラメータ

名前説明
useMobileTilesBooleanモバイルタイルを使用するかどうか。

リターン

StaticMap - チェーン用のこのマップ インスタンス。


setPathStyle(weight, color, fillColor)

新しいパスの作成時に使用するパスのスタイルを設定します。すでに追加されているパスには影響しません。

// Creates a map with paths set to be 1 pixel wide with a black line and a white fill.
var map = Maps.newStaticMap()
    .setPathStyle(1, Maps.StaticMap.Color.BLACK , 'red');

パラメータ

名前説明
weightIntegerピクセル単位の線の幅。
colorString線の色。「0xrrggbb」形式の文字列または Color の定数値。
fillColorString塗りつぶしの色、「0xrrggbb」の形式の文字列、または Color の定数値。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

setSize(width, height)

地図画像の幅と高さをピクセル単位で設定します。

// Creates a map 400px wide by 300px high.
var map = Maps.newStaticMap().setSize(400, 300);

パラメータ

名前説明
widthInteger画像の幅(ピクセル単位)。
heightInteger画像の高さ(ピクセル単位)。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API

setZoom(zoom)

地図で使用されるズーム ファクタまたは拡大レベルを設定します。

// Creates a map with a zoom factor of 10.
var map = Maps.newStaticMap().setZoom(10);

パラメータ

名前説明
zoomInteger0 ~ 21 の値。

リターン

StaticMap - チェーン用のこのマップ インスタンス。

関連ドキュメント

  • Google Static Maps API