RSS

Free Geo Location Script – Greet Your Visitors By Their City

Tue, Feb 17, 2009

Internet Marketing, Tips

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…

Click here to grab the 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.

, ,

41 Comments For This Post

  1. Paul Says:

    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

  2. Gary Says:

    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.

  3. Mikael Says:

    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

  4. Gary Says:

    Hhmmm, do you have javascript enabled? It might be something to do with your security settings.

  5. Aus Home Inventories Says:

    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

  6. Mikael Says:

    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

  7. Gary Says:

    Thats odd, not sure whats going on there. Seems to be working for the majority of people.

  8. Brian Simms Says:

    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.

  9. peter england Says:

    geo script a bit inaccurate. brings up redhill, surrey when we are in storrington west sussex. guess it may depend on the pop detected.

  10. Layne Says:

    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! :)

  11. Charles Lojko Says:

    Works great in every browser I’ve tried it in! Thanks :)

  12. jeff Says:

    Kick ass! Just what I was looking for, and.. it’s from Google API!

  13. Rich Alderton Says:

    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…

  14. John Petrov Says:

    After you upload this script on your web server you can test it with
    http://browsershots.org

    I hope this helps :)

    Regards,
    John

  15. Kotlina Klodzka Says:

    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?

  16. Ian Whyte Says:

    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.

  17. Tamara Bergen Says:

    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.

  18. 411 New York Says:

    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.

  19. 411 New York Says:

    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

  20. Carma Says:

    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

  21. Lance Says:

    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.

  22. Dyski Says:

    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.

  23. Rich Says:

    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

  24. Mark E Thurston Says:

    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.

  25. 411 New York Says:

    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.

  26. Dali Says:

    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’);
    }

  27. Steve Says:

    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

  28. JPG Says:

    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.

  29. GadgetSL Says:

    Demo didn’t work for me either. I also tried different browsers. Is there a new script or code that’s available?

  30. Chad Van Norman Says:

    Your test page is not working for me neither.

    All it says is…

    Greetings to all my blog readers in

    Chad Van Norman

  31. Kaaka Says:

    Great post…. Thanks a tonne…. :)

  32. Jesse Says:

    Thanks for the script. I get this error:
    ‘google.loader.ClientLocation.address’ is null or not an object

  33. Jesse Says:

    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.

  34. Christian Harms Says:

    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.

  35. bath mate Says:

    it really very good.
    I love it !
    I like it !
    thanks :) - .

  36. Jack Fisher Says:

    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

  37. Jack Fisher Says:

    today its not working at all -not stable
    also geobytes not working coincidence or Christmas holiday ?

    regards
    Jck

  38. Kim Says:

    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!

  39. Ram Ashish Says:

    I am trying to use this script but it is not working.

    Please help.

    Thanks

  40. pj Says:

    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

  41. pj Says:

    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; }

Leave a Reply