Mapping With Drupal - Alan Palazzolo [19]
Extending the Location module with the GMap module
Seeing the address of a business is useful, but often you want to display a map of a business. The easiest way to do this with the Location module is to use the GMap module. Like the Location module, the GMap module has been around since Drupal 4.6 in 2005, and its architecture reflects that. It is a very large module, but it integrates well with the Location module and is in use on tens of thousands of sites. It implements various parts of the Google Maps API on Drupal sites. The GMap module does three specific things:
It provides a clickable map for entering the location of a node.
It provides a map to display a node’s location.
It integrates with the Views module to display the results of a View on a Google map.
In this exercise we will cover the first two aspects of the module. The third aspect will be covered in Mapping with the GMap Module.
NOTE
The GMap module integrates with version two of the Google Maps JavaScript API. This version of the API was deprecated in May 2010. While it will continue to work, it lacks the newer features of the current version three Google Maps JavaScript API, such as mobile support, better speed, and removing the need for an API key. There are plans in the module’s issue queue to add support for version three, but this is a large task, so it is unlikely to happen soon. The GMap module works fine for most purposes despite this.
There is not yet a stable release of the GMap module for Drupal 7, but the development version works fine. Download the latest development release to your site’s modules directory.
Enable two modules: the GMap and GMap Location modules at admin/modules. There are some permissions that can be set for these modules, but they apply to components that are not used by these examples.
NOTE
The GMap Location module is only used in these examples to allow different kinds of markers to be selected for different content types. This module also creates a page that displays a map of all content on your site, which is rarely useful. For many websites, this module will not be necessary and does not need to be enabled. The GMap module, however, should be used.
Go to the GMap configuration page at admin/config/services/gmap. You will get a JavaScript error about the Google Maps API Key. Click OK to dismiss this message, and enter the same API Key that you entered earlier when configuring the Location module in Step 10. Leave all the other settings at their default value for now and scroll to the bottom of the page to click the “Save configuration” button.
NOTE
The process of setting up the Google Maps API key earlier in Basic configuration of location can actually be skipped because, when geocoding, the Location Module first tries to use the GMap module’s API key. If the GMap module is not installed, the Location module falls back to its own API key. In the Location Module exercise, we did not skip that configuration because we were seeing how the Location module worked when the GMap module was not installed.
If your site will be accessed from several different domains, use the Keys module to automatically switch to the correct API key for each domain.
When the page reloads after saving, you should not get the JavaScript error, and you should see a small Google Map of southern Europe and northern Africa. If you do not see these things, check that you have entered the API Key correctly.
Go to the Location module’s configuration page at admin/config/content/location/main and tick the “Use a Google Map to set latitude and longitude” checkbox. This will allow users to click on a map to set the business’s location instead of (or in addition to) entering an address. Click the “Save configuration” button.
Create some more “Drupal Company” content. From the “Add Content” page at node/add add a “Drupal Company.” Enter the name and description of a company. For this example, we will create a virtual company that