By: Ivan Zugec
http://webwash.net | http://twitter.com/webwashnet
- Location (https://drupal.org/project/location)
- GMap (https://drupal.org/project/gmap)
- Views (https://drupal.org/project/views)
- Ctools (https://drupal.org/project/ctools)
The Location module has been around for as long as I can remember, in Drupal 6 it was one of the only ways to store address and geographical coordinates. In Drupal 7, it is just as powerful.
Location comes tightly integrated with the GMap module, and most of the time you would use both modules together. Location is used to store addresses and GMap is used to display the addresses in a map. If you want to use something other than GMap for mapping, then look at the "IP Geolocation Views & Maps" module.
In this video, I'll show you how to store and geocode an address on an article using the Location module.
Before we begin, download Location, GMap, Views and Ctools. Then enable Location, "Location CCK", GMap, "GMap Location" and "Views UI".
Location allows you to display its address form in two ways: through a field using the "Location CCK" sub-module or directly in the node form using "Node Locations" sub-module. The module's data is always stored in the location table no matter which sub-module you use. I prefer to define a custom field using "Location CCK", but it's just a preference.
In this tutorial, we will use the "Location CCK" sub-module to display the address form.
So go to Structure, "Content types" and click on "manage fields".
Enter Location as the label, select Location from the field type drop-down list and click on Save.
We need the module to allow us to collect City, "State and Province" and "Postal code" on the address form. On this page, select Allow for City, "State and Province" and "Postal code".
Then click on "Save field settings". And click on "Save settings". Now that we have our field, let's go ahead and configure Location to geocode entered addresses.
Before we move on, let's quickly discuss Geocoding.
Geocoding is a process of converting a postal address (street name and suburb) into geographical coordinates like latitude and longitude. Most of the mapping services out there like Google Maps offer geocoding.
To have addresses geocoded, all we need to do is configure Location to use a particular geocoding service for a specific country.
So go to Configuration, Location and click on "Geocoding Options".
From the "Google Maps geocoding minimum accuracy" drop-down list select "Address level accuracy".
For this tutorial, I'll turn on geocoding just for Australia. But on a production site you would want to turn on geocoding for a few major countries.
Once you've selected a few countries, scroll to the bottom and click on "Save configuration".
Now that we have our field and geocoding setup, let's go ahead and make sure addresses are getting converted.
Go to Content, "Add content" and click on Article.
Fill out the form, and enter in a real address into the location field.
Once you save the form, you should see the address with coordinates.
So you followed along with this video, added a location field and configured geocoding. But when you add an address it's not being geocoded.
Here are four steps I would take to debug the issue.
First, check the values in the location table.
The first place to start your investigation is to look directly in the location table in the database. Always look directly in the location table and make sure there are values in the latitude and longitude columns.
Second, make sure you're connected to the internet.
Make sure you're development computer or production server has access to the internet. For geocoding to work, Location needs to use these services over the internet.
Third, use a real address
This may seem obvious, but make sure you use a real address.
And fourth, can't geocode addresses from a specific country
If you're having trouble with addresses not being converted from a specific country; then make sure you configure geocoding for that country in the "Geocoding options" page.
As you can see, storing addresses in Drupal is pretty easy using Location. It only takes a few minutes to configure the module. In part two of this series, we'll learn how to create a map using GMap and Views.