Google Maps and Drupal Location
One of the things I’ve enjoyed working on recently, has been using Drupal modules for location and Google Maps to present information in a new ways. As an illustration, I’ve set up a page on the Adopt CT First website, to show where there are various shelters and adoption events in Connecticut.
Before I get into the geekiness of how I set this up, let me tell you a little bit about Adopt CT First. The goal of this new group is simple. It is to get people who live in Connecticut and are looking for a new pet to check their local shelters first. By getting more people aware of local shelters, we can hopefully get more dogs adopted, and less killed. We can get more people to make sure their pets are spayed or neutered so the population of the shelters doesn’t continue to grow, and we can encourage others to become more involved with helping at local shelters.
Okay, back from the brief ad. Let talk tech. At the center of the page is Drupal’s Location module. This module allows users to associate geographic data with nodes that they create in Drupal, as well as their own user profile. There are three key modules you will want to use for this, Location, Node Locations and User Locations.
Yet where these modules really become useful is when you add the GMap module. This module allows users to access Google maps. The first thing you need to do when you set up Google Maps, is get a Google Maps API. The GMap module adds four modules, GMap, GMap location, GMap Macro Builder, and GMap Taxonomy Markers. I like to turn on all of them.
The first thing to do, is go to Administer, Site Configuration, GMap and enter the Google Maps API Key. There are lots of other things to set there, but usually, I just take the defaults.
The next step is to go to Administer, Site Configuration, Location and enable the display of locations. Then, click on the Geocoding options, and turn on Google Maps for geocoding in whatever locations you need it in. For those who aren’t aware of geocoding, it is the process of taking an address and converting it to latitude and longitude that can be used for creating maps.
With Location and Google Maps loaded and configured, the next step is to go to the different content types that you want to map. Go to Administer, Content management, Content Types, and for each content type, set up the location parameters. The default is to allow a maximum of zero locations. This prevents the location information from showing up. Set this to an appropriate level. Often, this will be one location. Yet in some cases, you might have multiple locations. For example, for looking at municipal efforts to save a dog, there may be a location for the town pound and a separate location for a rescue organization working with the town pound.
The second thing that needs to be changed is to allow the location data to collect city, state, and postal code. In my case, I also set the state to default to Connecticut. You can also require data to be entered, or force the data to the default.
One final thing I like to do when adjusting the location information for nodes is to omit the Coordinates in the display. As a geek, I like them, but as a general rule, my users don’t.
If you want to map users as well, you need to go to Administer, User management, User settings and set the same parameters as you did for the nodes. Again, if the maximum locations is zero, the form won’t show up. For me, I generally allow users to have one location. I often also omit their location name and street address for a little privacy.
With this, it is now time to set the GMap location information. To set things the way I want, I like to go to Build a GMap Macro. With this, you can play around to get the map centered and sized the way you want, with the controls and other aspects the way you want. I like to make my node maps 640x480, with the large controls, centered on the center of my state and zoomed in close enough to see most of the state. Once I’ve got the macro text from the Build a GMap Macro page, I paste it into the GMap Location settings found under Administer, Site Configuration, GMap Location.
A few other settings that have made this work better for me is to have the marker action Open a Link. Otherwise, the node information can take up too much screen space. I also like to use the small markers and use different colored markers for different types of content. In my case, an event uses a green marker, and pages use blue markers. As a final configuration option for nodes, I like to describe what the markers mean in the page header.
For user maps, I do something similar. I use the same macro text. I change the page header to explain what I’m doing and I use different colored markers for different roles of users.
The one last thing I like to do is override the markers based on taxonomy terms. If you’ve enabled GMap Taxonomy Markers, you can go to Administer, Content management, Taxonomy. The first thing you need to do is for the vocabularies you wish, click on edit vocabulary and at the bottom click on the button to enable GMap markers. The you need to list the terms and for each term that you want to assign a marker, click on the edit and set the Gmap Marker.
If you are using the Menu’s Module, you may want to Administer, Site Building, Menus and go to the Navigation menu. You can then edit the Node Locations menu item to have a title that works a little better for your needs. In my case, I changed it to Shelter and Event Locations.
With this, you can create some very interesting new ways to present data from a Drupal Website. Are you doing anything like this with your website? Got any hints about what worked well and what didn’t?