Mapping With Drupal - Alan Palazzolo [21]
[gmap zoom=9 |center=40.7143528,-74.0059731 |width=95% |height=300px |control=Small |type=Map]
Copy this macro (it can not be saved) and go back to the Location module’s configuration page at admin/config/content/location/main. Paste the macro you created into the “Location chooser macro” field. Click the “Save configuration” button.
Now, if you create a new Drupal company, you will see that the map is much larger, it is showing at a more useful scale, and it is centered on the location that you set. If you edit an existing Drupal company, you will see that the map is centered on that company’s location, but that the zoom level is the same as you set in the macro, and the width and height of the map are also as you set.
The GMap module has allowed for a richer user interface for adding location information. In Chapter 4 we will integrate this with the Views module, so as to display multiple locations on a map for people visiting the site.
Geocoding
In Adding geographic data to a node with the Location module we introduced the concept of geocoding. Geocoding is the process of creating spatial data from nonspatial information. Geocoding can be converting an address into latitude and longitude coordinate, or turning the name “Mount Everest” into a polygon. Going in the opposite direction, turning geospatial data into nongeospatial data, such as a coordinate into an address, is called reverse-geocoding.
NOTE
The process of geocoding, especially address conversion, usually involves a large amount of data and heavy processing power. This means that you are unlikely to create your own geocoding service, and it is why most of these modules integrate with existing services.
Modules
We have already worked through an example where the Location module geocoded the address that you entered for the Drupal company content type. To achieve similar results for the Geofield module, we will use the Geocoder and Addressfield modules. One other module that handles geocoding for Drupal 7 is the Geonames module, which will be briefly discussed.
Geocoder and Addressfield
To integrate with the OpenLayers and Geofield modules, the easiest way to allow users to enter an address and have it automatically geocoded is to install the Addressfield and Geocoder modules. For our example website, we will create a new content type to store Drupal events. The content type will contain the name of the event, a description of the event, a date, an address, and a latitude and longitude.
WARNING
Be careful not to confuse the Geocode and the Geocoder modules. They are two separate modules, though Geocoder is mostly a Drupal 7 port of Geocode, which is only for Drupal 6. There is a post in the Geocode issue queue that provides some background on the two modules and their future.
Download the latest stable release of the Addressfield module to your site’s modules directory.
Enable the Address Field module at admin/modules. There are no configuration or permissions changes needed for this module.
From the “Content types page,” add a new content type at admin/structure/types/add.
Enter Event as the Name.
For the Description, enter A Drupal event.
Change the “Title field label” to Event name.
All other options can remain as default for now. Click the “Save and add fields” button.
You are now taken to the “Manage fields” page for this content type at admin/structure/types/manage/event/fields. The third field listed should be “Body.” Click the “edit” link to change this.
Change the “Label” field to Event details. All other fields can stay with the default values. Click the “Save settings” button.
On the “Manage fields” page, go to the “Add new field” row. Enter Event location as the Label and event_location as the Field name. In the “Select a field type” drop-down, choose “Postal address.” In the Widget drop-down, choose “Dynamic address form” (the only choice).
Click the “Save” button at