February 05, 2007
MyMap: A Portable API for MapsCross-provider support for maps from Google, Yahoo, and MicrosoftLionel Laské
This API lets you switch from one map provider (like Google, Yahoo, or Microsoft) to another with minimum changes to your source code.
Lionel is a software architect at C2S, a software company based in France and a subsidiary of the Bouygues group. Lionel is also the author of Liogo, an open-source Logo compiler for .NET. Lionel can be contacted at llaske@c2s.fr.
A client who sells real estate wanted us to add interactive maps to his web site to showcase his listings. We immediately thought of using Google Maps. This seemed to be a good choice because it's free and popular. But for how long? Or what if Google decides to add advertisements on its maps? Of course, our client could always switch to another map provider, Yahoo Maps or Microsoft Virtual Earth, for instance, but at what cost?
Because Google, Yahoo, and Microsoft come with similar features, it occurred to us that a "portable" layer would let a web site switch from one map provider to another with a minimum change to source code. This is what I discuss in this article.
Most web sites that support interactive maps have similar features. If we want our portable layer to handle them, it should be able to:
MyMap
MyMap is the portable API I created to display maps in a web site with either Google Maps, Yahoo Maps, or Microsoft Virtual Earth. Here is the pseudointerface of this API in JavaScript. Each function matches one of the aforementioned features.
void MyMapGeocode(address, callback);
void MyMapInitialize
(mapname, lat, lng, zoom, mode);
Object MyMapAddMarker
(lat, lng, markertype, info);
void MyMapRemoveMarker(marker);
void MyMapSetZoom(zoom);
void MyMapGoto(lat, lng);
void MyMapTerminate();
Table 1 shows the provider-specific object to use and the methods to call for each feature.
Table 1: MyMap functions for each map provider.
I've implemented this interface for each provider in the respective files mymap_google.js, mymap_yahoo.js, and mymap_vearth.js. (These files are available electronically; see "Resource Center," page 5). Your web application needs to include the appropriate file depending on your map provider.
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|