Visitor Info Module
I have been working on a module to satisfy the feature request to map location of visitors to a website. I'm calling the module Visitor Info and it is active on my demo page.
Several people have requested a module that maps the location of visitors to a website. Most of the other contributed modules I have seen will map registered users on your site but not the anonymous visitors.
I have just contributed the module and you can download it from the project page here.
So basically what the module does is this, when someone visits your site, their IP address is captured and compared to those in the visitorinfo table. If the IP is already in the database, nothing happens. The geographic information for the IP is already captured so there is nothing to be done.
If the IP is not in the database however, then a call is made to the IPInfoDB.com XML API. It returns all the basic geographic information such as city, state, and country. But you also get back the latitude and longitude.
When a new visitor hits your site, a lookup is made and all that information is stored in the visitorinfo table. This module does two basic things at the moment.
- It creates a block that will show you the last 10* unique visitors to your site.
- It displays the geographic location of the last 200** visitors on a Google Map.
* This is not 100% accurate. The geolocation databases that resolves this information still lacks some data for certain parts of the world. The accuracy of the database is, as noted on the "IP Database" page at IPInfoDB.com,
"over 99.5% on a country level and around 80% on a city level for the US within a 25 mile radius..."
Currently, my code will skip any row lacking a city and state when printing the "Visitor Info" block. I think it looks better than having blank spaces in your block.
** This number is configurable from the settings page at Administer -> Settings -> Visitor Info.
Many people have the GMap module installed in order to display maps associated with nodes or users, etc. If GMap is installed and a Google API key already configured, Visitor Info will use that key to display its own map, so no configuration will be necessary. I must point out that the idea for that little piece of functionality came directly from the Simplemap project, which is really cool. Credit to mistergroove.
Of course, if you do not already have a Google API key, you can get one by going to the sign up page. It's a painless process and can be done in about 6 seconds.
So, this is my first actual contributed module and I'm very excited about it. I'm proud to be a member of the awesome Drupal community. I hope someone finds this module useful.
Posted: Dec. 26, 2009
It appears that some users are experiencing an SQL error such as the following;
I believe that is due to my use (mis-use is probably more accurate), of the db_rewrite_sql() function. From what I have been able to determine, it is supposed to be used in circumstances such as when you are doing a node listing, when other conditions need to be tested as well. For instance, the node module modifies queries for node listings to filter nodes protected by access fields. So basically what that means is that you would use db_rewrite_sql() if you were producing a listing of nodes but some of those nodes should only be shown to certain users. db_rewrite_sql()'s usage would ensure that those access rules were observed.
I believe the particular error above is due to calling db_rewrite_sql() with the wrong number of arguments. Those arguments are apparently needed when certain other modules are actually performing a rewrite of the sql. But as I think about it, I realize that I do not need to use that function, a simple db_query_range() would work just fine. The documentation for the database abstraction layer says regarding db_rewrite_sql() 'Use it for listing queries'. That's not what I am doing. db_query_range() is better suited since it 'runs a limited-range query in the active database'. I am just interested in building a data array to make available to JavaScript. So in this case I think I will remove the call to db_rewrite_sql() and just use db_query() instead.
I submitted a patch at http://drupal.org/node/668042. But I'm also gonna attach the latest to this page. Let me know your experiences with this module.
Posted: Jan. 3, 2010 I have just uploaded a new release to drupal.org. I have made some significant changes to the code, added a new map block and a few other things. Everything is covered in the README.txt file. I highly recommend this update. The changes I made to the code will take care of the map points with no corresponding information.
Posted: Jan. 4, 2010 Ok for whatever reason my upload of the newest version did not work yesterday. I downloaded the module and found that what is supposed to be the new version (6.x-1.2) is still all the old code from 6.x-1.1. I'm not real sure what that's all about but hopefully I can get the new one up pretty soon.
Posted: Jan. 4, 2010 Visitorinfo module is now updated. If you are using this module, please update to the current version (6.x-1.3) and give it a whirl.
- Development:

Comments
Location map not showing
I'm likely overlooking something basic, but the location map block doesn't appear. I can easily access the visitorinfo block and admin/reports/visitorinfo and map/user; but no luck on the location map.
Any ideas?
btw, love this module. Very cool
Currently, Visitor Info does
Currently, Visitor Info does not show a map in a block, only on the admin/reports/visitorinfo page is the map available. I am in the process of adding a few modifications such as better theming support and access to the map from places other than the admin area.
The block only shows city, state, and country of the last 10 visitors but I will see if I can work in a map block and release a new version.
Glad you like it!
Tim