Online Book Reader

Home Category

Mapping With Drupal - Alan Palazzolo [23]

By Root 324 0
will never be visible to a user of your website when they are creating events, so many of the settings on the final configuration page at admin/structure/types/manage/event/fields/field_event_geo are unnecessary. There are two important fields, though.

Under “Geocode from field,” select “Event location” (the field that contains the address).

NOTE

The Geocoder module can geocode any text field that contains properly formatted location data. It can also get the location from an uploaded JPEG photo that contains a geotag embedded as EXIF in the metadata. Many recent digital cameras and smartphones support this.

Under the “Geocoder” drop-down, select “Google Geocoder.”

Click the “Save settings” button.

The final step is to set the display for this field. Rather than displaying the latitude and longitude, the location of the event should be displayed on a map. Go to the “Manage Display” page for the Event content type at admin/structure/types/manage/event/display. For the “Event geo” field, change the Label to “”. Change the Format to “OpenLayers.” Click on the cog on the right side to configure the “OpenLayers display” widget. In the “OpenLayers Preset” drop-down, select “Geofield Formatter Map.” In the “Data options” drop-down, choose “Use full geometry.”

NOTE

The “Geofield Formatter Map” is the default map display that comes with the Geofield module. As shown in Figure 3-6, this default map is quite small-scale (zoomed out). If you wish to change this, you can create a new map preset, as described in Setting Up an OpenLayers Map. Including the Geofield placeholder layer in a new preset will make it show up in the list in the “OpenLayers Preset” drop-down.

Click the “Update” button to save the field display widget, and then click the “Save” button to save all the display settings.

The Event content type now displays a map with the geocoded location of the event, but is missing the crucial thing for an event: the date.

Download the latest release of the Date module to your site’s modules directory.

Enable the Date, Date API, and Date Popup modules. There are no important permissions or other configuration changes needed for these modules.

Go back to the “Manage fields” page for the Event content type at admin/structure/types/manage/event/fields and go to the “Add new field” row. Enter Event date as the Label and event_date as the Field name. In the “Select field” drop-down, choose “Date.” In the Widget drop-down, choose “Pop-up calendar.”

Click the “Save button” at the bottom of the page to create this field.

The default field settings should be fine, so just click the “Save field settings” button. The default values on the next page are fine too, so click “Save settings.”

Create a new Event. Include an address and a date using the “Event date” field. When you save the Event, the address should be geocoded and displayed on the map as shown in Figure 3-6.

Figure 3-6. A Drupal Event

Other geocoding modules and services


The Location and Geocoder modules for Drupal 7 are the only ones that will geocode addresses entered by users. However, there are some other geocoding services that can be integrated with Drupal if you are able to do some coding: among them are GeoNames and the GeoCommons Geocoder.

GeoNames is a huge geographic database that is available to download and use for free under a Creative Commons Attribution 3.0 License. It provides several services for looking up spatial information, such as searching for location information for place names, finding postal codes or Wikipedia articles near a particular location, or getting a list of postal codes for a particular country. It does not provide a geocoding service for an address, but it is very useful if you need other structured spatial data. The GeoNames module allows you to query these services from a Drupal site.

GeoCommons is a mapping platform and a community working to create an open repository of data and maps. One of the projects being worked on is an open source geocoder that can be installed on

Return Main Page Previous Page Next Page

®Online Book Reader