Google Mapping in FileMaker
UPDATE: I’ve written a follow up to this post which shows how to produce a map with multiple addresses.
Google Mapping in FileMaker
I’m sure you’ve seen the Web Viewer maps in FileMaker. Sure, they’re serviceable, but you’ve got no control. And with Google recently adding “Search Results” and “My Maps” to the screen as well (a laudable feature, to be sure), the available real estate for the actual map shrunk by almost half. What can be done? I’ll show you how to roll you own mapping engine using PHP and the Google Map API.
Using the built-in tools
Simple Google maps can be produced in FileMaker using the Web Viewer object. I’m sure you’ve all seen this:

This is the Web Viewer Setup for that example:

What’s wrong here?
The problem with this, in my opinion, is that the Search Results and My Maps area of the map takes up almost half of the screen. Further, you’ve got limited to no control of how this looks. And, one click on a link and the user is off browsing the web—not exactly what you want them to be doing.
Using the API
I decided to turn to the Google Maps API to attempt to solve these issues. The first step here is to sign up for a Google Maps API Key for the site you’ll be hosting your maps from (the maps will still need a home).
So as not to re-invent the wheel, my first step was to search for a PHP wrapper for the Google Maps API that I could use as the basis for my mapping API. I found one that I came to like called the Easy Google Map class. This PHP class wraps all the JavaScript in PHP calls, so a PHP-buff like myself can easily use it. You’ll need to download the Easy Google Map class (”EasyGoogleMap.class.php”) and install it on a webserver that supports PHP (the same one for which you got the Google Maps API key).
In this example, we’ll be staging the work at http://etc.proofgroup.com/fmcollective/, so the class will be located at http://etc.proofgroup.com/fmcollective/EasyGoogleMap.class.php. You can load this URL now, if you’d like, but you won’t get anything because it’s a PHP class and doesn’t return anything on its own.
The next step, of course, is to write a complementary PHP file that will actually be the mapping API. My thought was to make this simple to call from FileMaker, with a URL formatted like the following:
http://DOMAIN/MYCOMPLIMENTARYPHPFILE.PHP?addr=The+Address+To+Map
To do this I’ll need a PHP file that can grab the ‘addr’ parameter and process it according to the needs of the Easy Google Mapping Class in order to produce a map.
Here’s what my file (which I have named ‘googlemap.php’) looks like:
<?php
/*
* File Name: googlemap.php
* File URI: http://etc.proofgroup.com/fmcollective/googlemap.php
* Description: Google Map API wrapper script
* Version: 1.0
* Author: Mike Lee, The Proof Group LLC
* Author URI: http://www.proofgroup.com
*
* Copyright (c) 2007, The Proof Group LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in any form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Proof Group LLC nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROOF GROUP LLC ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALLBE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
require ‘EasyGoogleMap.class.php’;
# Google Maps API Key
$googlemaps_api_key = “XXX-XXX-XXX-INSERT-YOUR-KEY-HERE”;
# Get the ‘addr’ parameter from the GET request
$addr = $_GET['addr'];
$gm = & new EasyGoogleMap($googlemaps_api_key);
# Set address point(s)
$gm->SetAddress($addr);
$gm->SetInfoWindowText($addr);
$gm->SetSideClick($addr);
# To Enable/Disable Map Type (Map/Satellite/Hybrid)
$gm->mMapType = TRUE;
# Set map size
$gm->SetMapWidth(’700′);
$gm->SetMapHeight(’600′);
?>
<html>
<head>
<title>EasyGoogleMap</title>
<?php echo $gm->GmapsKey(); ?>
</head>
<body>
<center>
<?php
echo $gm->GetSideClick();
echo $gm->MapHolder();
echo $gm->InitJs();
echo $gm->UnloadMap();
?>
</center>
</body>
</html>
Copy that text and save it as ‘googlemap.php’ (you’ll want to insert your own API key where indicated). That file is now hosted here: http://etc.proofgroup.com/fmcollective/googlemap.php. You will want to put it in the same directory you put the EasyGoogleMap.class.php file.
A direct link to the file, which you can download, is here: Google Map PHP File. You will need to rename the file ‘googlemap.php’.
The fmcollective directory now looks like this:
.
|-- EasyGoogleMap.class.php
`-- googlemap.php
If you load the googlemap.php page right now, you’ll notice it’s blank, because you’ve not passed it any address to map (via the ‘addr’ parameter).
A fully working example URL is the following: http://etc.proofgroup.com/fmcollective/googlemap.php?addr=1600+Amphitheatre+Pkwy,+Mountain+View,+CA+94043.
Put the API into FileMaker’s Web Viewer
Now, let’s go back to the top and put this into FileMaker’s Web Viewer. Here’s a screenshot of what the finished product looks like:

The Web Viewer setup is for a ‘Custom Web Address’ set to the following:
"http://etc.proofgroup.com/fmcollective/googlemap.php?" & "addr=" & /*Address=*/ Contact Preferred Address::Street & ", " & /*City=*/ Contact Preferred Address::City & ", " & /*State=*/ Contact Preferred Address::StateProv & " " & /*Zip Code=*/ Contact Preferred Address::PostalCode
I hope you’ve enjoyed my first post and learned something useful. Comments are welcome.
Nice read and thanks for using EasyGoogleMap Class.
Have a nice day!
It’s worth pointing out the terms of use for the Google Maps API found here:
http://www.google.com/apis/maps/index.html
and here:
http://www.google.com/enterprise/maps/faq.html
Basically, you are okay to use it in an open, free non-commercial product for nothing; if–on the other hand–you are using it in a commercial, intranet or non-public solution, there is a license fee of at least$10,000.
So be very careful if you are planning to use any of the above article’s information in a solution for a client, and make sure you read the Terms and Conditions of use very carefully.
To make it usefull in all kinds of layout, you could make the width and height dynamic by adding the width and height as an extra parameter:
http://etc.proofgroup.com/fmcollective/googlemap.php?addr=1600+Amphitheatre+Pkwy,+Mountain+View,+CA+94043&width=400&height=300
I did an implementation with Microsoft Virtual Earth. With Virtual Earth you don’t need a public domain.
More info: http://www.microsoft.com/virtualearth/
Koen
Hi guys. I got it to work but not when the adress contains swedish charachters like å ä ö. I’ve tried with $charset = “iso-8859-1″; in both of the files but nothing works. Please help me.
I get an error:
Parse error: syntax error, unexpected T_CLASS in /clientdata/clients/u/l/ulearnit.com.au/www/googlemap/googlemap.php on line 35
Line 35 is:
require ‘EasyGoogleMap.class.php’;
Any ideas what could be wrong?
Could be a specific PHP variety or version difference.
Try enclosing the class name in parens:
require (’EasyGoogleMap.class.php’);
If that doesn’t work, try double quotes instead of single quotes.
Nice post Mike
Have you tried FusionMaps Pro for FileMaker? This is a flash mapping component for FM solutions, it renders animated data-driven maps through Web Viewer. The tool comes with a FileMaker Script Library as well.
I would like to know if there is a solution to this same problem within FileMaker itself, without PHP serving anything. That is, how can I get the web viewer to simply display the full image of the map without the sidebar?
Prior to FM9, the Web Viewer could only display URLs (not HTML directly). That’s why I originally started looking at tools that could convert a structured URL (i.e. http://example/map.php?addr=ADDRESS) into a suitable page for Google Maps. I couldn’t create the HTML locally and display it locally without resorting to other tricks (plug-ins to save a file locally, etc.) And those other tricks would make it brittle and add to the general complexity of making it work (although that’s open for debate). I settled on PHP because I happened to find some tools to make the Google Mapping easier (the “Easy Google Map” PHP class) and I have the PHP knowledge to make it work. That said, there are downsides to a server-based approach, notably the URL length limits mentioned above which impedes the total number of addresses that can be mapped at once.
With FM9, you can use the “data: URI scheme” (see http://en.wikipedia.org/wiki/Data:_URI_scheme) to hand-build the HTML and display it directly in a Web Viewer. This seems on the surface to be a much better choice, because the data don’t have to be sent across the internet to another server just to be displayed.
Here’s a simplified example:
“data:text/html,<html><body>Hello World!</body></html>”
If you put that into a Web Viewer (>=FM9), it will show “Hello World!”. Fairly boring, but the HTML can be as complex as required to get the job done.
The last step would be to write a process by which the JavaScript-based page is created directly in FM. I’ll leave that as an exercise for the reader. I’d be interested if anyone out there gets a prototype working.
Cheers,
Mike