Maps are becoming ubiquitous in web applications. They are being used as an effective and non-intrusive way of gathering geo-specific data from the user or to present geo-specific information to the user -- for example, for tracking reports of shipments. However even two years ago, embedding a map within an application was a specialized area that required a good understanding of Geographical Information Systems (GIS). This changed with the arrival of Google Maps and its corresponding set of APIs, known as the Google Maps API.
In the first two sections of this article I will deal with the whys and wherefores of the Google Maps API. In the third section I will detail the steps you need to take when using the Google Maps API. The last section will focus on a real world example based on the steps discussed in third section. That is the outline of the discussion.
What is the Google Maps API?
The access to most of the group of functions mentioned above is through the methods of the GMap2 class. The GMap2 class forms the basis of map creation, display and manipulation.
All of the aspects of any map provided by Google Maps are configurable, whether it's the enabling of dragging and information windows or continuous zooming. The methods of the GMap2 class sectioned under configuration enable configuration of the map. The following are the most often used methods for configuring maps:
enableDragging() enables the dragging of the map. Dragging is enabled by default.
disableDragging() disables the dragging of the map.
enableInfoWindow() enables the information window.
disableInfoWindow() disables the displaying of the information window.
The UI elements, using which the user controls the map and its functions, come under the controls category. There are two main methods related to controls. These are:
addControl(control, [position]) adds the specified control to the map at the place specified by the position parent. The position parameter is optional.
removeControl(control) removes the specified control from the map.
Both of the above functions take instances of the GControl class. There are five existing instances of the GControl class: GSmallMapControl, GLargeMapControl, GSmallZoomControl, GScaleControl and GMapTypeControl. These can be passed to the addControl() method to add controls to the map.