Track visitors using Google Maps

Create a table in your database, like 'visitor_map'. We will have these fields: id, ref, ip, location, longitude and latitude, execute the following code:

CREATE TABLE IF NOT EXISTS `visitor_map` ( `id` int(11) NOT NULL auto_increment, `ref` varchar(255) NOT NULL, `ip` varchar(15) NOT NULL, `location` varchar(32) NOT NULL, `longitude` float NOT NULL, `latitude` float NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

For ease of use, we'll now create a configuration file. Create a file called config.php and insert the following, changing the constant values to suit your database setup and Google Maps API key.

define('DB_HOST', 'localhost'); // Database host define('DB_NAME', 'Database'); // Database being used define('DB_USER', 'user'); // Database user define('DB_PASS', 'password'); // Database user's password /* Your Google Maps API key */ define('API_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); function IPtoCoords($ip) { $dom = new DOMDocument(); $ipcheck = ip2long($ip); if($ipcheck == -1 || $ipcheck === false) trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR); else $uri = 'http://api.hostip.info/?ip=' . $ip; $dom->load($uri); $location = (strpos($dom->getElementsByTagName('name')->item(1)->nodeValue, 'Unknown') === false) ? $dom->getElementsByTagName('name')->item(1)->nodeValue : $dom->getElementsByTagName('countryAbbrev')->item(0)->nodeValue; if($location == 'XX') return false; else { $dom->load('http://local.yahooapis.com/MapsService/V1/geocode?appid=' . Yahoo_Key . '&location=' . $location); $longitude = $dom->getElementsByTagName('Longitude')->item(0)->nodeValue; $latitude = $dom->getElementsByTagName('Latitude')->item(0)->nodeValue; return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); } }

Now that we can successfully gain the visitor's location, we can use this to build our finished visitor map.

Visitors map

Now paste this code to /templates/your_skin_dir_name/main/main.tpl and index.tpl

{php} require 'config.php'; mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); $ref = $_SERVER["HTTP_REFERER"]; $ip = $_SERVER['REMOTE_ADDR']; $userinfo = IPtoCoords($ip); $user = mysql_query('SELECT `location` FROM `visitor_map` WHERE `location` = '' . $userinfo['location'] . '''); if(!mysql_fetch_row($user) && $userinfo) mysql_query('INSERT INTO `visitor_map` (`ref`, `ip`, `location`, `longitude`, `latitude`) VALUES ('' . mysql_real_escape_string($ref) . '', '' . mysql_real_escape_string($ip) . '', '' . $userinfo['location'] . '', ' . $userinfo['longitude'] . ', ' . $userinfo['latitude'] . ')') or die(mysql_error()); {/php}

06.07.2009. 09:21


Comments

Buy OEM 14.04.2011. 15:05

I am having problem with the first link. It gives a 404 error? Thanks

Online Movie Store 18.04.2011. 16:36

You are a very clever individual!

oem software 22.04.2011. 13:06

How do I subscribe to the blog itself

Buy OEM Software 22.04.2011. 17:18

hooray; your writings on theater and writing much missed!

Buy OEM Software 22.04.2011. 17:41

You completed variousnice points there. I did a search on the subject matter and found nearly allpersons will have the same opinion with your blog.

Buy OEM Software 22.04.2011. 18:33

I don’t normally respond to posts but I'll in this case.

cigarrillos tabaco 23.04.2011. 00:48

Its little diffucult to understand this code

oem software 27.04.2011. 05:45

Love the blog here. Nice colors. I am definitely keeping up on the comments here.

Mens Diamond Watches 27.04.2011. 10:43

Thanks quite a lot for ones help! I believed getting the URL, though not the best way to take on it

oem software 28.04.2011. 05:56

Hey, really nice stuff you got here. Please accept my thank you for the article you provided.

sound trance 28.04.2011. 06:42

This is very interesting, You’re a very skilled blogger. I’ve joined your rss feed and look forward to seeking more of your excellent post.

Cialis sin receta 28.04.2011. 08:57

amazing register you’ve gain

house sound 29.04.2011. 05:40

Renew your rss feed please, I reading texts on blogs news via google chrome rss reader.

search mobile number 04.05.2011. 10:50

I want to show some thanks to this writer just for bailing me out of this type of difficulty.

Pink Golf Tees 06.05.2011. 09:26

The clarity in your blog post is simply great and i can assume you’re an expert on this subject.

Curtain Rod Black 06.05.2011. 09:27

Great article I've just added to my bookmark list.

article directory 08.05.2011. 10:35

I consider it to be a rather unique hybrid that combines qualities of both the Touch and the Nano.

submission article 08.05.2011. 11:06

There are a lot of things happening in the communications world

article submit 11.05.2011. 07:23

Terrefic post. U should submit your article at qateq.com

article submission 13.05.2011. 08:36

Fantastic article Interesting. U should submit your article at qateq.com

submit an article 23.05.2011. 06:11

really nice stuff you got here. Please accept my thank you for the article you provided. U should submit your article at qateq.com

dell inspiron 1011 23.05.2011. 06:17

I find myself coming to your blog more and more often to the point where my visits are almost daily now!

Prix de cialis 07.06.2011. 06:05

Thanks so much for one more excellent post.

Lateisha 08.06.2011. 00:44

Kudos! What a neat way of tihknnig about it.

jyryqnim 08.06.2011. 03:09

AeVRhC uersclibntro

Jimmy 08.06.2011. 05:12

Stands back from the keyboard in amazement! Tanhks!

pfmxhzae 09.06.2011. 08:29

ZNgJqX , [url=http://dunxkyzwlwzk.com/]dunxkyzwlwzk[/url], [link=http://nxyvatksgcte.com/]nxyvatksgcte[/link], http://rabtssivkxtb.com/

Tilly 09.06.2011. 11:40

AFAICT you've coveerd all the bases with this answer!

online play roulette 28.06.2011. 09:50

Mate, you are a good writer. Your text is really interesting. You should do it for a living

oem autocad 2009 28.06.2011. 14:31

This was the first place that told me the answer.
the time to read or visit the content or sites we have linked to below the
while the sites we link to below are completely unrelated to ours, we think they are worth a read, so have a look
below you'll find the link to some sites that we think you should visit
Must be nice to find yourself in a growing industry.
Keep up the good work
we like to honor other sites on the web, even if they aren't related to us, by linking to them.
I'm truly enjoying the design and layout of your blog.
This information really helped me, I am sharing with a few friends
Attractive section of content. I just stumbled upon your weblog and in accession capital to assert
You really make it seem so easy with your presentation
Nice site you have here
here are some links to sites that we link to because we think they are worth visiting
I like what you guys are up also
Great to find yourself in a growing industry.
Normally I don't learn post on blogs, but I wish to say that this write-up very compelled me to check out and do so!
I noticed your informative blog post earlier today and wanted to link to it
Great submit, I just given this onto a fellow employee who was doing a little investigation on this.
Im certain there are some additional nice instances in the long term for individuals who study your website.
Nice post! Resources such as the one you mentioned here will be extremely helpful to myself
I was very happy to see this blog
I wished to thank you for this well written post and I have you bookmarked
Thank you so much for giving everyone an extremely brilliant chance to discover important secrets from this web site
Good post but I was wondering if you could write a litte more on this subject
this was a really great post.
There is a lot of great info on this blog.
you have a great blog here! would you like to make some invite posts on my blog
It is the most boring game I have ever played.
Thanks so much for giving everyone an update on this matter on your site.
Your content are excellent and arrive in subjects
I like the valuable information you provide in your articles.
I’ll bookmark your blog and check again here regularly.
hmm it looks like your site ate my first comment
But wanna remark on few general things, The website pattern is perfect, the written content is really wonderful
I've been following your web site for some time now and finally got the courage to go ahead and give you a shout out
I won't be able to thank you more than enough for the blogposts on your web-site
just looking around some blogs, seems a pretty nice platform you are using.
This has been precisely the information I was looking for. Fantastic blog. Incredibly inspirational!
Now and then I'll stumble across a post like this and I'll recall that there really are still interesting pages on the web.
I would like to thanks for your time for the efforts you have made in writing this post.
This genuinely answered my problem, thank you!
I always wished to jot down in my site one thing like that.
Hi there just wanted to give you a quick heads up.
Keep functioning ,fantastic job!
Hey I am so delighted I found your site
It's taken me a short while to read all of the comments, but I truly enjoyed the article
Talking about the stock exchange is always interesting and enlightening
thanks for the awesome posting
I'm having troubles with subscribing to your blogs feed.
especially on websites you can find many different ads such as
I actually don't know how i found your blog because i had been researching information regarding politics
i have a fantastic time reading it, keep it up
Thanks for excellent information I was looking for this info for my mission.
I exceptionally loved reading your post
Is your theme custom made or did you download it from somewhere
I just wanted to thank you one more time for your amazing website you have designed here
This is such a great resource that you are providing and you give it away for free.
I enjoy seeing websites that understand the value of providing a prime resource for free.
I truly loved reading your post. Thanks
This was a really wonderful post.
Pretty! This was a really wonderful post. Thank you for your provided information.
I had been tiny bit acquainted of this your broadcast provided bright clear idea
Simply added to bookmarks, excellent post.
Great content, looking forward to tomorrow's update!
The Zune concentrates on being a Portable Media Player. Not a web browser.
I wanted to follow up and let you know how great I loved discovering your web blog today.
Great post, I admire the writing style
I love the dear info you suggest in your items. I will bookmark your website and have absolutely individual adolescents verify upward listed here in many cases.
Real nice design and wonderful content material, nothing else we want
Very interesting topic, thanks for putting up.
thanx for your patience and sorry for the inconvenience!
I just added you on my blogroll, come visit my site and see what you think
The moderators here are extremely delicate, please be watchful what you publish!
I loved as much as you will receive carried out right here.
Cool post, nice blog btw.
I do believe all the concepts you've introduced on your post.
I wanted to thank you for this excellent read!! I definitely loved every bit of it.
I've you bookmarked your site to see the new stuff you post.
That's great.very helpful,thanks a lot
I’ll probably be again to read much more, thanks for that info.
I'll bookmark your blog and take the feeds also
I want to start blogging too what do you think, which blog platform is good for noob
I like the efforts you have put in this, regards for all the great blog posts.
bless you for the article, I might come back later to view out your other posts.
Good morning, thx for the blog post
I may come back later on to check out out your other posts.
Wow,Fantastic article,it's so helpful to me,and your blog is very good,I've learned a lot from your blog here
Hi there, thanks a lot for the page, I will probably come back later to look at out your other posts.
You post awsome articles Just bookmarked !!!
Excellent post. I was checking constantly this blog and I'm impressed!
I care for such info much. I was seeking this certain info for a long time
Simply, the put up about dating is admittedly the best on this laudable topic.
Where do these trolling folks get this stuff?
A good number of these replies on this post look like trash; You should filter them out.
This is really interesting, You're a very skilled blogger.
I have joined your rss feed and look forward to seeking more of your wonderful post
This is my first visit to your blog
Most awessome post!
I certainly liked reading all that is written on your blog

Write a comment

* = required field

:

:

:


7 + 7 =