background image
Eric's picture

In this blog entry I'll show how you can create a Google map showing where your users are located using CCK, Content Profile, Views, GMap, and Location modules. Once you've downloaded and extracted those modules, enable the following modules (and set permissions accordingly):

Content
Location
Location CCK
Content Profile
GMap
GMap Location
Views
Views UI

Next you'll need to configure these new modules. On the GMap settings page (admin/settings/gmap) you'll need to add your API Key and enable the setting to Use AutoZoom. On the Location settings page (admin/settings/location) enable the checkbox to use a Google Map to set latitude and longitude and enable JIT geocoding. On the geocoding settings page (admin/settings/location/geocoding), you'll have to enable Google Maps for the desired countries.

The Content Profile module creates a new content type called "Profile". You'll need to add a new field to this content type for the user's location (admin/content/node-type/profile/fields). Enter a label for the node type (Location), enter a field name (field_location), choose "Location" for the field type, and choose "Location Field" for the widget.

On the next screen edit the Locative information sections (Collection and Display) to your liking, and save the field settings. For my example, I enabled Street location, Additional, City, State, Postal code, Country, and Coordinate Chooser.

Now if you create your profile node (node/add/profile) you can enter your location information and save the new node. If all is working at this point, if you return to the profile node edit screen and scroll down to the location information, you should now see a marker on map for your location and the geocoded information will be shown.

Now you can add a new view (admin/build/views/add) to show the user's profile locations. Enter a name for your view, choose node for the view type, and click the next button. Add a new filter for "Node: Published" is true and "Node: Type" is one of "Profile". Add a new relationship for Content: Location (field_location). Add fields for "Location: Latitude" (using the Location relationship), "Location: Longitude" (using the Location relationship), and any additional fields you'd like to display in the GMap marker (title, parts of the address, etc). For the Style of the view choose "GMap". For the GMap style settings, select "Choose latitude and longitude fields" for the Data Source and ensure the Latitude and Longitude fields as set.

Lastly, I added a page view so I could see the results in action..

ps> special thanks to everyone at CommonPlaces for their great technical discussions about these modules!

Can't get it to work!

When I try to follow your instructions I see slightly different things on my screen. Were you using Drupal 6.x?

For example when trying to set a relationship in Views I don't get "Content: Location" as an option.

Also, I do not get a drop down list for the data source for the GMap style. I get radio buttons instead.

Am I doing something wrong?

awesome tutorial. I spent

awesome tutorial. I spent almost 10 hours on this stuff but couldnt figure out.
i,m trying to implement something like this
http://www.lonelyplanet.com/india/delhi/qutb-minar

very similar to this. close map, open map and in the map the markers of all the nodes should be there but the map should point to the node im viewing right now and when i clicking on any marker that info bubble should come with link to the corresponding node and zoom in link.

Im thankfull for your blog and i will be very very very thankfull if u help me out.

Thanks

Thanks!

Great tutorial, just what I needed. Thanks! :)

Modules Versions?

Hi Eric,

Thanks for the tutorial

I am trying to do to something like this with using gmap, location and views. But there is a problem with one of the modules. I cant find the problem. Can you write the versions of the modules you used for this tutorial.

Bug that may cause problems

Hi. I followed this tutorial to a T and could not get the GMap marker to display correctly. If you're having this problem go here for a patch.

Thanks for the tutorial!

Eric's picture

6.x

At the time I wrote this, I think I was running the latest (stable) 6.x versions:

Views 6.x-2.6
Location 6.x-3.1-rc1
GMap Module 6.x-1.1-rc1
Content Construction Kit (CCK) 6.x-2.5

Thanks

you are a prince among men. Something of following what you said made it work. I have been trying to put help in. I probably put in 14 hours.

I'm using views 6.x-2.10 and

I'm using views 6.x-2.10 and under Data source get the following option 'Fields named "latitude" and "longitude" @@@TODO', which doesn't appear to work - no google map appears on the page it is supposed to, just the view title. Thanks for the very useful tutorial though. I'm going to have a look in the views code to see if I can work out what's going on. Has anybody else had this issue?