Geotagging your photos

Every photo that you take with your digital camera contains embedded information about that photo.  This information, referred to as EXIF data, contains information about the time the photo was taken, as well as other information such as the aperture settings, exposure information, or other relevant information.

One type of information that can be captured is the location the picture was taken.  The location is captured as a set of map coordinates.  If the photos you take contain this type of EXIF data, the Geocode module can read these coordinates, and store them in Geo for use in maps and searches.

Adding geolocation information to photos

Before you can do any mapping or location searches for photos in Drupal, you must make sure that the necessary EXIF data is contained in your photos.  Many newer cameras and phones with GPS units built in do this automatically.  For example, the camera contained in Apple's IPhone or camera phones that use the Android operating system can embed their locations into the images they take.

Alternatively, there are various means of adding this information to pictures after you have taken them.  If you have a GPS receiver you can carry it with you as you take photos.  Then when you process your photos you can use software tools to combine the information from the GPS with your photos.  This method uses the time information stored in the photo to match the photo with a location from your GPS track, so make sure you have your time set correctly on both devices!

Adding your photos to your Drupal site

Now that you know how to make sure your photos have geolocation information you need to know how to upload these photos to Drupal and pull out the geolocation so you can use it.   For this recipe we assume you're on Drupal 6.  Along wth Drupal 6 you'll need a few contrib modules to complete this recipe.  These modules will allow us to create an Photo content type, add an image upload field to it, and add a field to capture the geolocation of the photo.

First let's add an image upload mechanisim.   For this you'll need:

Once you've downloaded the modules, enable the following from your http://<mysite>/admin/build/modules page in the CCK section:

  • Content
  • FileField
  • ImageField

Adding an image field to your content type

While you can use any content type you'd like, I'll be referencing a Photo content type in this recipe.  For more information on creating content types see http://drupal.org/node/231019.  Once we've created our Photo content type we need to add the ability to upload our photo and pull out it's geolocation. 

Let's start with the photo upload.  For this we need to add a field to our Photo content type.  Got to http://<mysite>/admin/content/types and click on "manage fields" for your Photo content type.   This takes you to the screen where you can add additional fields to your content type.   Create a new field with the label "Image" and name "image".  For the field type select "File" and for operations select "Image".  Now click "Save".

You'll now be taken to a form where you can set some additional configurations for your new image field.  For the most part you can accept the default parameters, scroll through each section and when you're done click "Save field settings".

Getting the geolocation from your photos

The image field will give us the ability to upload a photo, now we need to add another field to get the geolocation from the image.  For this we need to add a "Geospatial data" field to our content type.  To access this information we'll need the Geo and Geocode modules.  Geo provides a base for storing geospatial data, like the information stored in your images.  The Geocode module provides the mechanisim to pull the geolocation out of your photo during upload, and then pass it to Geo for storage.

 Enable the following from your http://<mysite>/admin/build/modules page:

From CCK section:

  • Geocoded value

From Geo section:

  • Geo
  • Geo Field
  • Geocode

With the modules turned on, we're ready to add another field.  Go back to your content types page (http://<mysite>/admin/content/types) and click "manage fields" again for your content type. 

Now start creating a new field and provide it with a label and name.  For the type select "Geospatial data" and for the operations select "Geocoded value from another field", like so:

Save your field and you'll be taken to a new form which lets you select additional options for this field.  The first thing you need to do is tell the Geospatial data field to gather information from our Image field.   Scroll down through the list of fields and find the one labeled Image.   Select this field by checking the box next to the label.  For the Geocode handler select Image field and for the Return value select point.   Now scroll to the bottom of the form and click "Save field settings".

Using the geolocation

You now have the basic pieces for creating a new photo node, uploading your photo, and having it's location (if it has one!) pulled out and stored for you.   You can use the geolocation to show where your picture was taken on a map or filter based on it's location.

For a simple display, you can setup the GMap module by going to http://<mysite>/admin/settings/gmap and pasting in a Google Maps API Key.  Now go to the display settings for you content type by accessing http://<mysite>/admin/content/types, clicking edit, and then clicking on the "Display fields" tab.  Once there, find the field for your photo location and set it's teaser and full node display options to GMap.

Now when you create a new photo node (http://<mysite>/node/add/photo) you can upload your photo and it will automatically have it's geolocation pulled and stored for use.  The Gmap and Gmap+Geo modules provide the basic formatter, showing you on a map where that photo was taken.   You can expand beyond this using other formatters such as Openlayers, or by creating a view mapping all of the photos on your site.  

For an example of this in action, visit http://geoblog.geojune.org/.

Related modules: