Information Made Visible: Using the Google Maps View in Drupal 5

Submitted by ethan on

Google MapsThe views module is a very powerful way of displaying information stored in nodes. Coupled with CCK for creating custom content types, it is possible to store and visualize data in very interesting ways. One of these ways is displaying location information on an embedded Google Map using a view type provided by the Gmaps module.

The location module associates physical address information with nodes so that content can be localized. It will also automatically geocode physical addresses - that is, turn street addresses into latitudes and longitudes - using various geocoding services. We've had success using Google's service.

Geocoding is an important step - the map will not draw markers without a longitude and latitude. If you have everything set up correctly, adding a street address and postal code and submitting the changes should automatically populate the latitude and longitude fields. Sometimes it can be finicky; for instance, if the street address and postal code do not match, but in general it works. Another issue arises when importing a large number of nodes. Sometimes the automatic geocoding does not run, but can be prompted by submitting the node manually or perhaps by republishing on mass.

Once your nodes have longitudes and latitudes, make a page view using the Gmap view type. Add the Location:Longitude and Location:Latitude fields, and then filter for the content type you wish to view. Once you've done that, the view should show a Gmap with markers representing the nodes.

Modules Required:

  • Gmaps
  • Location

Steps:

  1. Add location information to the content type (admin/content/types/[content type]) - be sure to include the latitude and longitude fields, and most likely the street address and postal code if you need to geocode them to get lat/long.
  2. Add the content you wish to display with address information, and ensure then lat/long fields are automatically being populated.
  3. Create a view using the Gmaps type, adding the lat/long information as fields and filtering for your content type.
  4. Enjoy!

Section: 

Code: 

AttachmentSize
Example - Coffee Shops in Ottawa839.42 KB

Add new comment