Interface with the Google Static Maps API v2 in apps.
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit behind barelyknown:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



GoogleStaticMap.cls makes it easy to interact with the Google Static Map API v2 from a application. The class is self contained with no external dependencies.

Simple Example

If you're OK with default formatting, you can request a map with only one or two lines of code.

In your Apex controller:

String[] afcEastCities = new String[]{'Boston, MA','New York, NY','Buffalo, NY','Miami,FL'};
String afcEastMapUrl = new GoogleStaticMap().addMarkers(afcEastCities).url;

In your Visualforce Page:

<apex:image value="{!afcEastMapUrl}" />


Use Custom Icons

The formatting can be controlled at the lowest level if you need to communicate more detail or would like to implement a specific design.

In your Apex controller:

GoogleStaticMap.MapMarker dolphins = new GoogleStaticMap.MapMarker('Miami, FL').icon('');
GoogleStaticMap.MapMarker bills = new GoogleStaticMap.MapMarker('Buffalo, NY').icon('');
GoogleStaticMap.MapMarker jets = new GoogleStaticMap.MapMarker('New York, NY').icon('');
GoogleStaticMap.MapMarker patriots = new GoogleStaticMap.MapMarker('Boston, MA').icon('');
String afcEastMapUrl = new GoogleStaticMap().addMarkers(new GoogleStaticMap.MapMarker[]{dolphins,bills,jets,patriots}).url;

In your Visualforce Page:

<apex:image value="{!afcEastMapUrl}" />


Draw Paths

Paths can also be drawn, with our without markers and with custom formatting.

In your Apex controller:

String[] homes = new String[]{'Albany, NY','Wellesley, MA','New York, NY','Pittsburgh, PA','01945','Ann Arbor, MI','Chicago, IL'};
GoogleStaticMap.MapPath moves = new GoogleStaticMap.MapPath(homes).color('0x000000ff');
String movesUrl = new GoogleStaticMap().addPath(moves).url;

In your Visualforce Page:

<apex:image value="{!movesUrl}">



The class implements the majority of the attributes enabled by the Google Static Maps API. Look at the source for details (and feel free to write up detailed documentation if I don't get to it first!).


This class started as a port of the googlestaticmap Ruby repository by Brent Sowers. Big thanks to him for the main design and inspiration.