允許建立及建立靜態地圖圖片。
以下範例說明如何使用這個類別建立紐約市劇院的地圖 (包括附近的火車站),並在簡單的網頁應用程式中顯示該地圖。
// 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)
將新位址新增至目前的路徑定義。
// 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();
參數
名稱 | 類型 | 說明 |
---|---|---|
address | String | 要新增的地址。 |
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);
參數
名稱 | 類型 | 說明 |
---|---|---|
latitude | Number | 新標記的緯度, |
longitude | Number | 新標記的經度。 |
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');
參數
名稱 | 類型 | 說明 |
---|---|---|
address | String | 新標記所在的位置。 |
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]);
參數
名稱 | 類型 | 說明 |
---|---|---|
points | Number[] | 定義路徑的經緯度組合所構成的陣列。 |
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);
參數
名稱 | 類型 | 說明 |
---|---|---|
polyline | String | 編碼的折線。 |
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();
參數
名稱 | 類型 | 說明 |
---|---|---|
latitude | Number | 點的緯度, |
longitude | Number | 點的經度。 |
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)
參數
名稱 | 類型 | 說明 |
---|---|---|
latitude | Number | 點的緯度, |
longitude | Number | 點的經度。 |
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');
參數
名稱 | 類型 | 說明 |
---|---|---|
address | String | 必須在地圖上顯示的地址。 |
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 網域可能會暫時受到限制,
參數
名稱 | 類型 | 說明 |
---|---|---|
contentType | String | 要轉換的 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);
參數
名稱 | 類型 | 說明 |
---|---|---|
latitude | Number | 中心的緯度。 |
longitude | Number | 中心的經度。 |
Return 鍵
StaticMap
— 此鏈結用於鏈結。
另請參閱
setCenter(address)
使用地址設定地圖的中心。
// Creates a map centered on Times Square, using its address. var map = Maps.newStaticMap().setCenter('Times Square, New York, NY');
參數
名稱 | 類型 | 說明 |
---|---|---|
address | String | 中心地址。 |
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);
參數
名稱 | 類型 | 說明 |
---|---|---|
imageUrl | String | 指定要做為標記自訂圖示的網址。您可以使用 PNG、JPEG 或 GIF 格式的圖片,不過建議使用 PNG。 |
useShadow | Boolean | 表示標記應根據圖像的可見區域及其不透明度/透明度產生陰影。 |
Return 鍵
StaticMap
— 此鏈結用於鏈結。
另請參閱
setFormat(format)
setLanguage(language)
設定地圖上的文字所使用的語言 (顯示圖片)。
// Creates a map with the language set to French. var map = Maps.newStaticMap().setLanguage('fr');
參數
名稱 | 類型 | 說明 |
---|---|---|
language | String | BCP-47 語言 ID。 |
Return 鍵
StaticMap
— 此鏈結用於鏈結。
另請參閱
setMapType(mapType)
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');
參數
名稱 | 類型 | 說明 |
---|---|---|
size | String | 來自 MarkerSize 的常數值。 |
color | String | 格式為「0xrrggbb&」的字串,或來自 Color 的常數值。 |
label | String | 含有單一字元 A-Z 或 0-9 的字串。 |
Return 鍵
StaticMap
— 此鏈結用於鏈結。
另請參閱
setMobile(useMobileTiles)
設定是否針對行動裝置使用專用圖塊集。
// Creates a map that uses mobile-friendly tiles. var map = Maps.newStaticMap().setMobile(true);
參數
名稱 | 類型 | 說明 |
---|---|---|
useMobileTiles | Boolean | 是否使用行動圖塊。 |
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');
參數
名稱 | 類型 | 說明 |
---|---|---|
weight | Integer | 線條寬度 (以像素為單位)。 |
color | String | 線條顏色,格式為「0xrrggbb」的字串,或是 Color 的常數值。 |
fillColor | String | 填滿顏色、格式為「0xrrggbb」的字串,或 Color 的常數值。 |
Return 鍵
StaticMap
— 此鏈結用於鏈結。
另請參閱
setSize(width, height)
設定地圖圖片的寬度和高度 (以像素為單位)。
// Creates a map 400px wide by 300px high. var map = Maps.newStaticMap().setSize(400, 300);
參數
名稱 | 類型 | 說明 |
---|---|---|
width | Integer | 圖片寬度 (以像素為單位)。 |
height | Integer | 圖片的高度 (以像素為單位)。 |
Return 鍵
StaticMap
— 此鏈結用於鏈結。
另請參閱
setZoom(zoom)
設定地圖使用的縮放比例係數 (即放大等級)。
// Creates a map with a zoom factor of 10. var map = Maps.newStaticMap().setZoom(10);
參數
名稱 | 類型 | 說明 |
---|---|---|
zoom | Integer | 這個值介於 0 至 21 之間 (含首尾)。 |
Return 鍵
StaticMap
— 此鏈結用於鏈結。