Mass import of addresses with OpenLayers, Geocoder and Feeds

Last updated on
30 April 2025

Introduction

By using Geofield, Geocoder, Address Field, Feeds, and Openlayers, you can create maps almost entirely from the GUI for most use cases, but at the moment Feeds can't import to Address Fields because it's dynamic. This might change in future.
Address field is useful because it gives you the proper number of fields for an address. The number and order of fields are dynamically updated when you select a country, because different countries have different address formats. Geocoder takes that address field and turns it into latitude and longitude points (“lat-longs”). Geocoder takes the lat-longs that it created and stores them in a Geofield.
Address field is great when you manually add locations, but when you want to mass import locations, you should use a regular text field and the Feeds module.

Instructions

Summary

For mass importing addresses you need to create

  1. a Feeds importer,
  2. a content type with an address field and a Geofield, which will geocode the address field,
  3. two views: one in which to have your page display and one in which to have your open data overlay,
  4. and a mapping (preset) within Openlayers.

Required modules

Step-by-step

Create a content type

First create a content type with a single text field in which you put your address information. Geocoder can only use data from one field (or or addressfield).
Geocoder uses the Google API, which can supply latitude and longitude for most kind of addresses, even if they are only partial.

Create OpenLayers Data Overlay

Second, create an OpenLayers Data Overlay view. (See a detailed tutorial at Getting started.) Add the Geofield as “Latitude only” and “Longitude only” by choosing the Geofield you created for your content type; you will need to select the Geofield one within the Field section and then choose “Latitude only” for the Formatter, and then you have to add the Geofield again and use “Longitude only” for the Formatter. Then filter your content type to be the content type you created in step one. Limit your items to display to be 50 items, in order to ensure your server can handle the map we are creating. Now create a view with a Page display. The Format should be Openlayers Map. Create a path in the page settings. This view we have just create we will call “View Map” for the purposes of this tutorial.

After saving that view, go to yoursite.com/admin/structure/openlayers/maps, click “Clone” for the “Geofield Widget Map (Default)”. Name this preset “My First Map”. Go to “Center and Bounds” to pick the zoom and focus you want for your map. Go to Layers and Styles and make sure that “OSM Mapnik: The main OpenStreetMap” is enabled. Then make sure that the first view you created is Enabled and Activated within the “Overlay Layers” section. Within Behaviors, check off “Cluster Features” (and the name of your first view within the Cluster Features submenu). check off the Mouse Drag Pan, Pan and Zoom Bar Controls (with Pan Icons), Pop Up for Features (with the first view you created), and Zoom to Max Extent. The Behaviors can be problematic because several of them are incompatible with other Behaviors, so read the descriptions carefully and if the map doesn't work, take away some of the behaviours you have chosen. Now save your map.

Go to View Map, the second view you created. Within Format Settings, select the map preset called “My First Map”. Save the view. Go to the URL you specified earlier in this view, and you will see your finished map.

Install geoPHP library

Install the geoPHP library, which is necessary for Geofield:

geoPHP is a library for doing basic geospatial operations entirely in PHP and is required by geofield.

If you enable geofield using drush with drush-make installed, then geoPHP library will be automatically downloaded. To download manually:

If it is not already present, create a libraries directory inside your Drupal installation’s sites/all folder.
Download the geoPHP library from https://github.com/downloads/phayes/geoPHP/geoPHP.tar.gz
Unarchive the library files and place in sites/all/libraries
Your directory structure should look like: /sites/all/libraries/geoPHP/geoPHP.inc

Help improve this page

Page status: Not set

You can: