I’m sure you’ve come across online advertisements or websites that mention your City, State etc.
Most often they tend to be ads for online dating sites saying, “meet and chat to people right now in xxxxxxx”, or something to that effect.
When I first started to look into how to do this on my own sites the only reliable methods I found seemed to be pretty costly, but a few weeks back I found a simple way to do it for free, and it seems to be pretty accurate as far as I can tell.
Click here to see how accurate it is…
It’s just one simple block of code…
First paste the above code into note pad. Then copy and paste it again into your websites html wherever you want the location text to appear. The text will adhere to any style attributes applied to it on the page.
Also, the part of the script that reads, “Walnut Creek, CA”, is what will be appear when no location is able to be found, so you can change that to whatever you like.
Hope you get some use out of this and let me know how accurate the script was for you when you clicked the demo above.
Later.
Gary McCaffrey.




February 17th, 2009 at 12:46 am
Couldn’t get this to work on my blog… but your test page worked perfectly.
Have you been able successfully embed in a page or post on WordPress?
Would love to integrate this into my on-page copy…
Paul
February 17th, 2009 at 12:50 am
Hi Paul,
I’m testing a way to integrate this with wordpress now. Hopefully it works and I’ll update my post with instructions.
Gary.
February 17th, 2009 at 1:12 am
Gary,
Your demo isn’t working for me. I’ve tried it in IE7, FF3, Chrome, Safari, etc… It may just be on my end, but IE gave me this error:
“‘google.loader.ClientLocation.address’ is null or not an object”
Line: 2, Char: 1
Don’t know if anyone else is getting an error as well… knowing my history, it’s on my end.
Cheers!
Mikael
February 17th, 2009 at 1:23 am
Hhmmm, do you have javascript enabled? It might be something to do with your security settings.
February 17th, 2009 at 2:20 am
On going to http://www.garymccaffrey.com/geotest.html chrome and IE7 give “Greetings to all my blogreaders in” the rest is blank. Firefox displays the script on the screen! We do not seem to have other problems with scripts etc. As we have tested and installed your other stuff & advice so far with no errors, we assume this must be glitch! Love your twitter advice Gary….Good stuff
February 17th, 2009 at 2:46 am
Gary,
Yeah, sorry meant to give you more details. I have JS enabled and brought my security all the way down.
If it’s working for others, pay it no mind, just something I have to trouble shoot on my end it looks.
Cheers!
Mikael
February 17th, 2009 at 3:18 am
Thats odd, not sure whats going on there. Seems to be working for the majority of people.
February 18th, 2009 at 7:49 am
I uploaded the script to my site and it worked fine in Firefox. If you click on the Search Engine Tab, your City and region should show.
February 18th, 2009 at 11:11 am
geo script a bit inaccurate. brings up redhill, surrey when we are in storrington west sussex. guess it may depend on the pop detected.
March 8th, 2009 at 10:35 pm
Just thought I would let you know that my location came up about 70 miles off, and our city is many times larger than the one that came up.
Love your work!
March 9th, 2009 at 7:54 am
Works great in every browser I’ve tried it in! Thanks
March 20th, 2009 at 4:09 am
Kick ass! Just what I was looking for, and.. it’s from Google API!
March 27th, 2009 at 2:31 am
Accurate? Accurate my hat!
The test page puts my location as London, Surrey. Only two problems:
1. I’m about 300 miles away from London
2. London wasn’t in Surrey, last time I checked
Seems like this code doesn’t travel outside the US too well…
March 29th, 2009 at 8:23 am
After you upload this script on your web server you can test it with
http://browsershots.org
I hope this helps
Regards,
John
May 5th, 2009 at 10:50 am
Too bad you didn’t put it on your site. We could check it out right now.
Or am I blind and it’s somewhere here?
May 27th, 2009 at 3:36 am
Gary,
Tried but gave an approximate but incorrect location
St Lucia Qld was the response. This is an inner western suburb of Brisbane. I live on the other side of Brisbane near Cleveland Qld. Perhaps my ISP is in St Lucia.
I am only new at this game so keep up the good work helping. I started using tweeter getter last night so cannot offer any results as yet. Zeb Olsens’s video give a lot of answers.
May 30th, 2009 at 11:40 pm
I’m confused! How and why would I use the Geo Location Script? I tested it and got Welcome to all my blog readers in Cape Coral on top of a blank page. I’m assuming the test worked? Don’t have a blog yet…soon… I have a website tho.
June 3rd, 2009 at 4:04 pm
Test page worked great.
We hope this script/code will pass validation so we can use it for http://411newyork.org or we will have to toss it out unfortunately.
June 10th, 2009 at 10:26 pm
Error found while checking this document as HTML 4.01 Transitional!
1 Error, 3 warning(s)
* No Character Encoding Found! Falling back to UTF-8
* Unable to Determine Parse Mode!
* No Character encoding declared at document level
Any Ideas what to do?
Test Page
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.garymccaffrey.com%2Fgeotest.html&charset=%28detect+automatically%29&doctype=Inline&group=0
July 28th, 2009 at 10:33 pm
The geolocator was close. It said Chandler, AZ, and I’m in Phoenix on the border of Tempe. Maybe my ISP provider is based there?
Cool beans, though.
- Carma
August 7th, 2009 at 7:54 am
Interestingly this script had my location out by just over 100kms. A number of these scripts get my location wrong by about this distance or more while others do get the correct town every time I test them.
August 13th, 2009 at 12:08 pm
Could be helpful for people who e.g. are providing selling across their neighborhood or just have a store nearby. But for the most web users (especially bloggers) there is no need for such plugin. I think that most of website users don’t care about where are their friends coming from, that is secondary importance issue. When someone is trying to get some money from own blog it becomes almost sure that readers from all over the world could drop by and see what’s going on.
August 17th, 2009 at 3:29 pm
Works great!! I’ve been looking everywhere for something like this..Thanks..I’ll be using this on my sales page at Teach English Online
September 11th, 2009 at 2:11 pm
The script will use the location of the server ISP the person who is viewing it uses. So if their ISP is located a town or two away, the greeting will be off by a few miles, but should be close enough. I always see those messages on sites as being in the next town over to me, but that is because that is where my ISP’s server is located.
September 21st, 2009 at 12:12 pm
It is working perfectly and validates.
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.411newyork.org&charset=%28detect+automatically%29&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.654
Our hats off to you.
October 13th, 2009 at 1:51 pm
The code below found on http://checkbrowser.info is seen to be shorter but got the same result. May i know what’s the different? Which should i use?
if (google.loader.ClientLocation != null) {
document.write(google.loader.ClientLocation.address.country);
} else {
document.write(‘Not Detected’);
}
October 23rd, 2009 at 8:35 pm
Your test page was spot on for my (small) town in UK. I can understand peoples concern over having uses for this type of thing, BUT, with a bit of lateral thinking it could prove beneficial ie on Isohunt website last time I looked their sidebar advertising dating sites (not that I encourage dating sites) they use a similar type of code to make the girls advertised for dating appear to be in your own area.
Just need to think about it for a while for a more (ethical?) type of advertising
November 4th, 2009 at 2:25 pm
I’ve been looking for something like this but your demo is not working. I tried IE, firefox (no scripts blocked) and chrome. I’m located in Toronto btw.
November 8th, 2009 at 3:39 am
Demo didn’t work for me either. I also tried different browsers. Is there a new script or code that’s available?
November 10th, 2009 at 6:19 pm
Your test page is not working for me neither.
All it says is…
Greetings to all my blog readers in
Chad Van Norman
November 19th, 2009 at 6:14 am
Great post…. Thanks a tonne….
December 2nd, 2009 at 5:18 am
Thanks for the script. I get this error:
‘google.loader.ClientLocation.address’ is null or not an object
December 2nd, 2009 at 5:55 am
It seems to work fine for users in larger cities. The match returns null when the ip can’t be matched to a location by Google.
December 7th, 2009 at 6:48 am
The google geo location is not so accurate and dont returns city/country! hostIP.com or ipinfodb.com are better. But the better solution is aggregate the returned positions from all the ip Location providers and midlle the position: Check this out: http://united-coders.com/christian-harms/free-ip-location-script
Thanx for looking.
December 21st, 2009 at 11:52 am
it really very good.
- .
I love it !
I like it !
thanks
December 27th, 2009 at 6:43 am
I live in Turkey,not working for me ,
Its working in my home , but not working in the office which is only 1 km away from home
thanks anyway
Jack
December 27th, 2009 at 3:19 pm
today its not working at all -not stable
also geobytes not working coincidence or Christmas holiday ?
regards
Jck
January 26th, 2010 at 3:40 am
Awesome! It works just fine in WordPress with the php code plugin (widget). It didn’t work with the text widget.
Thanks! You’ve saved me a great deal of time and effort!
August 9th, 2010 at 1:09 pm
I am trying to use this script but it is not working.
Please help.
Thanks
August 26th, 2010 at 7:50 am
GARY: ur link “Click here to see how accurate it is…” only displays:
Greetings to all my blog readers in
there is no geo ip shown, actually there is nothing shown after that message. Im using flock 2.6.1 on a mbp macbook pro
August 26th, 2010 at 8:02 am
KIM or anyone: i installed the php code plugin widget however its called (maybe they changed & updated name)
Executable PHP widget
Like the Text widget, but it will take PHP code as well. Heavily derived from the Text widget code in WordPress.
Deactivate | Edit
Version 2.1 | By Otto | Visit plugin site | Donate
anyways i dont know php but i can copy
stuff. ive installed the plugin on my site, the only thing i see is an Edit link to go directly to the code as opposed to a newbie friendly form box where i would just copy and paste the script.
Plugin Files
* php-code-widget/execphp.php
* php-code-widget/readme.txt
can someone insert the code correctly and email me the updated php please dont hate me i know i suck
portablejon@gmail.com
in this code???
‘widget_execphp’, ‘description’ => __(‘Arbitrary text, HTML, or PHP Code’)); $control_ops = array(‘width’ => 400, ‘height’ => 350); $this->WP_Widget(‘execphp’, __(‘PHP Code’), $widget_ops, $control_ops); } function widget( $args, $instance ) { extract($args); $title = apply_filters( ‘widget_title’, empty($instance['title']) ? ” : $instance['title'], $instance ); $text = apply_filters( ‘widget_execphp’, $instance['text'], $instance ); echo $before_widget; if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ob_start(); eval(‘?>’.$text); $text = ob_get_contents(); ob_end_clean(); ?> ”, ‘text’ => ” ) ); $title = strip_tags($instance['title']); $text = format_to_edit($instance['text']); ?> <label for="get_field_id(‘title’); ?>”> <input class="widefat" id="get_field_id(‘title’); ?>” name=”get_field_name(‘title’); ?>” type=”text” value=”" /> <textarea class="widefat" rows="16" cols="20" id="get_field_id(‘text’); ?>” name=”get_field_name(‘text’); ?>”> <input id="get_field_id(‘filter’); ?>” name=”get_field_name(‘filter’); ?>” type=”checkbox” /> <label for="get_field_id(‘filter’); ?>”> <?php } } add_action('widgets_init', create_function('', 'return register_widget("PHP_Code_Widget");')); // donate link on manage plugin page add_filter('plugin_row_meta', 'execphp_donate_link', 10, 2); function execphp_donate_link($links, $file) { if ($file == plugin_basename(__FILE__)) { $donate_link = 'Donate‘; $links[] = $donate_link; } return $links; }