Location, Location, Location

Using the Location module and Google Maps for postal code searching in the UK

Photo of Greg Harvey
Sat, 2009-03-28 13:16By greg

I'm just finishing the first phase of a job using the GMap and Location modules in tandem (along with Views) to create assorted location maps driven by the Google mapping API. I have to say, the last time I tried to use these modules it was about a year ago in Drupal 5.x and it was a struggle. I allowed a decent chunk of time to getting this all working, given past experiences, so I was pleasantly surprised to discover things have moved along a *lot* since I last looked.

Firstly, the Location module now just works. You can set it on the user form and on a content type basis, what information is collected, default values, etc. Wonderful! You can also set a Location CCK field with the contributed CCK integration, if you don't want to use the default Location fields provided on the node add/edit forms.

There is now built in longitude and latitude discovery for some countries (most importantly for me, this is supported out of the box for the UK and the US) - you simply tell the Location module which service to use to map a postal/zip code to co-ordinates (in my case Google Maps) and when your users submit a postal code for their location (or the location of a node, e.g. a shop) then the Location module will ask Google (or the service you selected) for the corresponding longitude and latitude co-ordinates so it can place a pin in the map. Marvellous!

The GMap module allows you to pick a marker for each content type (which is then respected by the GMap views you create) so you can set globally which markers correspond to which content types (shop, parking, ATM, whatever). And of course, making your own markers is nice and easy too.

And the icing on the cake is the GMap view "display" type. You can create a view of type "Node", set up all your filters as though you were creating a list of nodes on a listings page and create a display of type "GMap" and your nodes will appear on a Google Map. Everything will be done, correct marker selected and you can enter a custom Google Map macro to position the centre point, set the size, set the default marker, etc. on a view-by-view basis.

To give you an idea, I have created a store finder for the UK, a user base map for the UK and the US, well installations in South Africa and a store nomination feature (where users can say where they would like products stocking in the future to allow the retailer to target popular stores and areas) all in the space of a day. Powerful stuff.

If you have mapping requirements for anything from a store finder to tracking an expedition, I strongly recommend you look at the Location, GMap and Views combination. It is extremely powerful. The only caveat is the availability of the postal code look-up API is sketchy. But if you can get users to enter longitude and latitude (e.g. tracking an expedition) then this is not a problem anyway.

I'll post a link to this in action just as soon as the site is launched. =)