Interface with the Google Static Maps API v2 in Force.com 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.
Permalink
Failed to load latest commit information.
GoogleStaticMap.cls
README.markdown

README.markdown

Introduction

GoogleStaticMap.cls makes it easy to interact with the Google Static Map API v2 from a Force.com 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}" />

simpleExampleMap

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('http://goo.gl/2pFtB');
GoogleStaticMap.MapMarker bills = new GoogleStaticMap.MapMarker('Buffalo, NY').icon('http://goo.gl/7uRWT');
GoogleStaticMap.MapMarker jets = new GoogleStaticMap.MapMarker('New York, NY').icon('http://goo.gl/fRrSw');
GoogleStaticMap.MapMarker patriots = new GoogleStaticMap.MapMarker('Boston, MA').icon('http://goo.gl/ieqVq');
String afcEastMapUrl = new GoogleStaticMap().addMarkers(new GoogleStaticMap.MapMarker[]{dolphins,bills,jets,patriots}).url;

In your Visualforce Page:

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

iconExample

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

movesExample

Details

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!).

Credit

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