Overview
This tutorial will show you how to set up a Drupal site that can accept address information for a node, look up related geospatial information, and store it for future reference. This can facilitate basic mapping and more complex geospatial uses, which will be addressed in separate tutorials. In the spirit of proper separation of concerns, this tutorial focusses on capture and storage, leaving presentation for a separate tutorial.
Assumptions
This tutorial assumes that you are familiar with creating and editing nodes, setting up content types with CCK, and installing and configuring modules.
Requirements
- Latest release of Drupal 6.x
- CCK module (this tutorial was done with CCK 6.x-2.3)
- Postal (this is an optional module for cases where highly-structured input data is desired. [e.g. in political district matching projects]. This tutorial will not cover using the Postal module.)
- Geo module (latest development release)
- Geocode module (latest development release)
The process
Module setup
- Download and install CCK, Geo and Geocode
- On the module configuration page, enable the following modules:
- In the CCK section, enable Geocoded value
- In the Geo section, enable Geo, Geofield and Geocode
- Note: There is no configuration necessary (or even available) for these modules. You may want to review the permissions made available by these modules.
Set up a content type for your geocoded content
To use Geo, you'll need a content type that will contain some information that will be used to geocode data (such as an address).
Visit http://<yoursite>/admin/content/types/add and create your new content type. For the sake of illustration, call it "Place".
Add a two new fields to your Place content type
The first field is for capturing the user-provided data for your Place:
For the sake of illustration, call the first field "Location". Select "Text" for the field type. For "Form element to edit the data," you will most likely want "Text field" for cases where users are providing their own location info. Clicking the "Save" button will take you to a page with more options for this field. No changes are necessary here, so just click "Save Field Settings" at the bottom.
The second field is for containing the geocoded data that the Geocode module returns after analyzing the "Location" field you just created.
Create this second field for your content type. For the sake of illustration, call it "Coded Location." Select "Geospatial data" for type and "Geocoded value from another field" for "Form element to edit the data."
After hitting "Save," you will be taken to the field configuration page. Here, you will see a list of all other fields that could be sources of geodata. Find the first field you created above, "Location," and select its checkbox. The configuration options immediately below—Geocode handler and Return value—can be left at defaults (currently "geocode_google" and "point"). Save your changes.
Try it out
Create a Place under http://<yoursite>/node/add/place. Provide a title and a body. In the Location field, provide some address information, such as street number, street name, and zip code.
See what happens.
