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";

另請參閱

方法

方法傳回類型簡短說明
addAddress(address)StaticMap將新位址新增至目前的路徑定義。
addMarker(latitude, longitude)StaticMap使用點 (lat/lng) 在地圖上新增標記。
addMarker(address)StaticMap使用地址在地圖上加入標記。
addPath(points)StaticMap使用點陣列新增地圖路徑。
addPath(polyline)StaticMap使用編碼的折線為地圖新增路徑。
addPoint(latitude, longitude)StaticMap在目前的路徑定義中新增點 (lat/lng)。
addVisible(latitude, longitude)StaticMap新增必須在地圖中顯示的點 (lat/lng) 位置。
addVisible(address)StaticMap新增必須在地圖上顯示的地址位置。
beginPath()StaticMap啟動新的路徑定義。
clearMarkers()StaticMap清除目前的標記組合。
clearPaths()StaticMap清除目前的路徑組合。
clearVisibles()StaticMap清除目前的可見位置組合。
endPath()StaticMap完成開頭為 startPath() 的路徑定義。
getAs(contentType)Blob傳回此物件中的資料,以轉換為指定內容類型的 blob。
getBlob()Blob取得 Blob 的圖片資料。
getMapImage()Byte[]取得原始圖像資料做為位元組陣列。
getMapUrl()String取得地圖圖片的網址。
setCenter(latitude, longitude)StaticMap使用點 (lat/lng) 設定地圖的中心。
setCenter(address)StaticMap使用地址設定地圖的中心。
setCustomMarkerStyle(imageUrl, useShadow)StaticMap設定建立新標記時使用的自訂標記圖片。
setFormat(format)StaticMap設定地圖圖片的格式。
setLanguage(language)StaticMap設定地圖上的文字顯示語言 (顯示圖片)。
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要新增的地址。

Return 鍵

StaticMap — 此鏈結用於鏈結。


addMarker(latitude, longitude)

使用點 (lat/lng) 在地圖上新增標記。

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

參數

名稱類型說明
latitudeNumber新標記的緯度,
longitudeNumber新標記的經度。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


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新標記所在的位置。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


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[]定義路徑的經緯度組合所構成的陣列。

Return 鍵

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編碼的折線。

Return 鍵

StaticMap — 此鏈結用於鏈結。


addPoint(latitude, longitude)

在目前的路徑定義中新增點 (lat/lng)。

// 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點的經度。

Return 鍵

StaticMap — 此鏈結用於鏈結。


addVisible(latitude, longitude)

新增必須在地圖中顯示的點 (lat/lng) 位置。

// 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點的經度。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


addVisible(address)

新增必須在地圖上顯示的地址位置。

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

參數

名稱類型說明
addressString必須在地圖上顯示的地址。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


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();

Return 鍵

StaticMap — 此鏈結用於鏈結。


clearMarkers()

清除目前的標記組。

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

Return 鍵

StaticMap — 此鏈結用於鏈結。


clearPaths()

清除目前的路徑組合。

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

Return 鍵

StaticMap — 此鏈結用於鏈結。


clearVisibles()

清除目前的可見位置組合。

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

Return 鍵

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();

Return 鍵

StaticMap — 此鏈結用於鏈結。


getAs(contentType)

傳回此物件中的資料,以轉換為指定內容類型的 blob。這個方法會在檔案名稱中加上適當的副檔名,例如「quofile;myfile.pdf"」。但其假設,最後一個月後面的檔案名稱部分 (如果有) 是必須取代的現有副檔名。因此「quoList;ShoppingList.12.25.2014"」將變成「ShoppingList.12.25.pdf"」。

如要查看轉換的每日配額,請參閱 Google 服務的配額。新建立的 Google Workspace 網域可能會暫時受到限制,

參數

名稱類型說明
contentTypeString要轉換的 MIME 類型。對大多數 blob 而言,'application/pdf' 是唯一有效的選項。如果圖片是 BMP、GIF、JPEG 或 PNG 格式,則 'image/bmp''image/gif''image/jpeg''image/png' 中任何一個都是有效的。

Return 鍵

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.

Return 鍵

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'));

Return 鍵

Byte[]:採用所選圖片格式的地圖圖片。


getMapUrl()

取得地圖圖片的網址。

// 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");

Return 鍵

String — 網址:地圖圖片網址。


setCenter(latitude, longitude)

使用點 (lat/lng) 設定地圖的中心。

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

參數

名稱類型說明
latitudeNumber中心的緯度。
longitudeNumber中心的經度。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


setCenter(address)

使用地址設定地圖的中心。

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

參數

名稱類型說明
addressString中心地址。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


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指定要做為標記自訂圖示的網址。您可以使用 PNG、JPEG 或 GIF 格式的圖片,不過建議使用 PNG。
useShadowBoolean表示標記應根據圖像的可見區域及其不透明度/透明度產生陰影。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


setFormat(format)

設定地圖圖片的格式。

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

參數

名稱類型說明
formatString來自 Format 的常數值。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


setLanguage(language)

設定地圖上的文字所使用的語言 (顯示圖片)。

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

參數

名稱類型說明
languageStringBCP-47 語言 ID。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


setMapType(mapType)

設定要顯示的地圖類型。

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

參數

名稱類型說明
mapTypeString來自 Type 的常數值。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


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');

參數

名稱類型說明
sizeString來自 MarkerSize 的常數值。
colorString格式為「0xrrggbb&」的字串,或來自 Color 的常數值。
labelString含有單一字元 A-Z 或 0-9 的字串。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


setMobile(useMobileTiles)

設定是否針對行動裝置使用專用圖塊集。

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

參數

名稱類型說明
useMobileTilesBoolean是否使用行動圖塊。

Return 鍵

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 的常數值。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


setSize(width, height)

設定地圖圖片的寬度和高度 (以像素為單位)。

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

參數

名稱類型說明
widthInteger圖片寬度 (以像素為單位)。
heightInteger圖片的高度 (以像素為單位)。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱


setZoom(zoom)

設定地圖使用的縮放比例係數 (即放大等級)。

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

參數

名稱類型說明
zoomInteger這個值介於 0 至 21 之間 (含首尾)。

Return 鍵

StaticMap — 此鏈結用於鏈結。

另請參閱