Google Apps Script

Class StaticMap

Allows for the creation and decoration of static map images.
The example below shows how you can use this class to create a map of New York City's Theatre District, including nearby train stations, and display it in a simple web app.

 
function doGet(event) {
   // 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]);
   }

   // Create the user interface and add the map image.
   var app = UiApp.createApplication().setTitle('NYC Theatre District');
   app.add(app.createImage(map.getMapUrl()));
   return app;
 }
 

See also

Methods

MethodReturn typeBrief description
addAddress(address)StaticMapAdds a new address to the current path definition.
addMarker(latitude, longitude)StaticMapAdds a marker to the map using a point (lat/lng).
addMarker(address)StaticMapAdds a marker to the map using an address.
addPath(points)StaticMapAdds a path to the map using an array of points.
addPath(polyline)StaticMapAdds a path to the map using an encoded polyline.
addPoint(latitude, longitude)StaticMapAdds a new point (lat/lng) to the current path definition.
addVisible(latitude, longitude)StaticMapAdds a point (lat/lng) location that must be visible in the map.
addVisible(address)StaticMapAdds an address location that must be visible in the map.
beginPath()StaticMapStarts a new path definition.
clearMarkers()StaticMapClears the current set of markers.
clearPaths()StaticMapClear the current set of paths.
clearVisibles()StaticMapClears the current set of visible locations.
endPath()StaticMapCompletes a path definition started with beginPath().
getAs(contentType)BlobReturn the data inside this object as a blob converted to the specified content type.
getBlob()BlobGets the image data as a Blob.
getMapImage()Byte[]Gets the raw image data as a byte array.
getMapUrl()StringGets the URL of the map image.
setCenter(latitude, longitude)StaticMapSets the center of the map using a point (lat/lng).
setCenter(address)StaticMapSets the center of the map using an address.
setCustomMarkerStyle(imageUrl, useShadow)StaticMapSets the custom marker image to use when creating new markers.
setFormat(format)StaticMapSets the format of the map image.
setLanguage(language)StaticMapSets the language to be used for text on the map (where avaialbe).
setMapType(mapType)StaticMapSets the type of map to be shown.
setMarkerStyle(size, color, label)StaticMapSets the marker style to use when creating new markers.
setMobile(useMobileTiles)StaticMapSets whether or not to use specialized tile sets for mobile devices.
setPathStyle(weight, color, fillColor)StaticMapSets the path style to use when creating new paths.
setSize(width, height)StaticMapSets the width and height of the map image in pixels.
setZoom(zoom)StaticMapSets the zoom factor, or magnification level, used for the map.

Detailed documentation

addAddress(address)

Adds a new address to the current path definition.

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

Parameters

NameTypeDescription
addressStringan address

Return

StaticMap — the StaticMap instance to facilitate chaining of calls


addMarker(latitude, longitude)

Adds a marker to the map using a point (lat/lng).

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

Parameters

NameTypeDescription
latitudeNumberthe latitude of the new marker
longitudeNumberthe longitude of the new marker

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


addMarker(address)

Adds a marker to the map using an address.

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

Parameters

NameTypeDescription
addressStringthe address at wich to place the new marker

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


addPath(points)

Adds a path to the map using an array of 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]);
 

Parameters

NameTypeDescription
pointsNumber[]an array of latitude/longitude pairs that define the path

Return

StaticMap — the StaticMap instance to facilitate chaining of calls


addPath(polyline)

Adds a path to the map using an encoded 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);
 

Parameters

NameTypeDescription
polylineStringan encoded polyline

Return

StaticMap — the StaticMap instance to facilitate chaining of calls


addPoint(latitude, longitude)

Adds a new point (lat/lng) to the current path definition.

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

Parameters

NameTypeDescription
latitudeNumberthe latitude of the point
longitudeNumberthe longitude of the point

Return

StaticMap — the StaticMap instance to facilitate chaining of calls


addVisible(latitude, longitude)

Adds a point (lat/lng) location that must be visible in the map.

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

Parameters

NameTypeDescription
latitudeNumberthe latitude of the point
longitudeNumberthe longitude of the point

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


addVisible(address)

Adds an address location that must be visible in the map.

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

Parameters

NameTypeDescription
addressStringan address that must be visible in the map

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


beginPath()

Starts a new path definition. Calls to addAddress() and addPoint() will define each new vertex in the path. The path is completed when endPath() is called.

 
// 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 — the StaticMap instance to facilitate chaining of calls


clearMarkers()

Clears the current set of markers.

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

Return

StaticMap — the StaticMap instance to facilitate chaining of calls


clearPaths()

Clear the current set of paths.

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

Return

StaticMap — the StaticMap instance to facilitate chaining of calls


clearVisibles()

Clears the current set of visible locations.

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

Return

StaticMap — the StaticMap instance to facilitate chaining of calls


endPath()

Completes a path definition started with beginPath().

 
// 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 — the StaticMap instance to facilitate chaining of calls


getAs(contentType)

Return the data inside this object as a blob converted to the specified content type.

Parameters

NameTypeDescription
contentTypeStringthe MIME type to convert to. For most blobs, 'application/pdf' is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of 'image/bmp', 'image/gif', 'image/jpeg', or 'image/png' are also valid.

Return

Blob — the data as a blob


getBlob()

Gets the image data as a 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 — An image of the map in the selected image format.


getMapImage()

Gets the raw image data as a byte array.

In general, prefer using getBlob() which allows for simpler interactions with other services.

 
// 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[] — An image of the map in the selected image format.


getMapUrl()

Gets the URL of the map image.

 
// Creates a map centered on Times Square and gets the URL.
 var map = Maps.newStaticMap().setCenter('Times Square, New York, NY');
 Logger.log(map.getMapUrl());
 

Return

String — URL the map image URL


setCenter(latitude, longitude)

Sets the center of the map using a point (lat/lng).

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

Parameters

NameTypeDescription
latitudeNumberthe latitude of the center
longitudeNumberthe longitude of the center

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


setCenter(address)

Sets the center of the map using an address.

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

Parameters

NameTypeDescription
addressStringthe address of the center

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


setCustomMarkerStyle(imageUrl, useShadow)

Sets the custom marker image to use when creating new markers. Markers that have already been added will not be affected.

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

Parameters

NameTypeDescription
imageUrlStringspecifies a URL to use as the marker's custom icon. Images may be in PNG, JPEG or GIF formats, though PNG is recommended.
useShadowBooleanindicates that the marker should have a shadow generated, based on the image's visible region and its opacity/transparency

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


setFormat(format)

Sets the format of the map image.

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

Parameters

NameTypeDescription
formatStringa constant value from Format

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


setLanguage(language)

Sets the language to be used for text on the map (where avaialbe).

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

Parameters

NameTypeDescription
languageStringa BCP-47 language identifier

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


setMapType(mapType)

Sets the type of map to be shown.

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

Parameters

NameTypeDescription
mapTypeStringa constant value from Type

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


setMarkerStyle(size, color, label)

Sets the marker style to use when creating new markers. Markers that have already been added will not be affected.

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

Parameters

NameTypeDescription
sizeStringa constant value from MarkerSize
colorStringa string in the format "0xrrggbb" or a constant value from Color
labelStringa string containing a single character A-Z or 0-9

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


setMobile(useMobileTiles)

Sets whether or not to use specialized tile sets for mobile devices.

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

Parameters

NameTypeDescription
useMobileTilesBooleanwhether or not to use mobile tiles

Return

StaticMap — the StaticMap instance to facilitate chaining of calls


setPathStyle(weight, color, fillColor)

Sets the path style to use when creating new paths. Paths that have already been added will not be affected.

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

Parameters

NameTypeDescription
weightIntegerthe width of lines in pixels
colorStringthe line color, as a string in the format "0xrrggbb" or a constant value from Color
fillColorStringthe fill color, a string in the format "0xrrggbb" or a constant value from Color

Return

StaticMap — the StaticMap instance to facilitate chaining of calls.

See also


setSize(width, height)

Sets the width and height of the map image in pixels.

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

Parameters

NameTypeDescription
widthIntegerthe width of the image in pixels
heightIntegerthe height of the image in pixels

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also


setZoom(zoom)

Sets the zoom factor, or magnification level, used for the map.

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

Parameters

NameTypeDescription
zoomIntegera value from 0 - 21+

Return

StaticMap — the StaticMap instance to facilitate chaining of calls

See also

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.