Online Book Reader

Home Category

Mapping With Drupal - Alan Palazzolo [18]

By Root 292 0
or other site that is not accessible for free by the public.

Tick the box and enter the URL for your site. It is best to enter the domain without the www (e.g., http://mappingdrupal.com). If you have a development or local version of your site, this API key will work on subdomains of this URL (e.g., http://staging.mappingdrupal.com or http://local.mappingdrupal.com), but the API key will not work on other domains (e.g., http://localhost/mappingdrupal or http://mappingwithdrupal.com). You will need to sign up for a different API key for those other domains.

Copy your new API Key (the long string of letters and numbers) to the “Google Maps API Key” field on your site and click the “Save configuration” button.

Adding geographic data to a node with the Location module


Now that we have the necessary modules enabled and the Google Maps API key stored, we need to create the content type to store information about Drupal development companies. The content type will contain the company’s name, a short description, and its address.

From the Content types page, add a new content type at admin/structure/types/add.

Enter Drupal Company as the Name.

Enter A Drupal development company as the Description.

Change the “Title field label” to Company 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/drupal-company/fields. The third field listed should be “Body.” Click the “edit” link to change this.

Change the “Label” field to Company description. 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 Company location as the Label and company_location as the Field name. In the “Select a field type” drop-down, choose “Location.” In the Widget drop-down, choose “Location Field.”

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

The next screen that comes up is the Field settings for the Company location field. This determines both what information will be collected when someone creates a new Drupal company, and also what information will be displayed about that company when someone views the site.

Under “Collection settings”, change the Collect drop-down for “Location name” to “Do not collect.” We are using the title field for this information. Leave “Street location,” “Additional,” “Country,” and “Coordinate Chooser” set at “Allow.” Change “City,” “State/Province,” and “Postal code” to “Allow.” There is also a field to set a default value for each of these fields, and to use the “Force Default” option to only allow users to enter an address for a particular country, state, etc.

The Display Settings section allows certain fields to be hidden. Leave these all visible for now. Click the “Save field settings” button.

On the final screen, tick the “Required field” checkbox so that a location has to be set for this content type. Click the “Save settings” button.

Create some “Drupal Company” content. From the “Add Content” page at node/add, add a “Drupal Company.” Enter the name and description of a company, and a full street address. Click the “Save” button. You should now see something similar to Figure 3-5. If you do not see the address, check the modules page at admin/modules to make sure that you did not accidentally enable the Node Location module (see Warning).

Figure 3-5. A Drupal Company

It is useful to see the latitude and longitude below the address so that we know that geocoding has been successful, but we do not need to display this to people visiting our site. In this example we do not want to show the “See Map” link either. Go to the “Manage fields” page for the content type at admin/structure/types/manage/drupal-company/fields/field_company_location and edit the “Company location” field. At the very end of this form, under the “Display Settings” section, check the “Map link” and “Coordinates” checkboxes to prevent

Return Main Page Previous Page Next Page

®Online Book Reader