You can use an other API to locate user if it doesn't work. (NOTE: W3School script didn't worked on my computer)
Here are some API :
Maxmind.com
Maxmind.com plugin (already installed on geoplugin.net) :
http://www.geoplugin.net/json.gp?ip=8.8.8.8&jsoncallback=callback
You can use it JSONP:
<script type="text/javascript" src="http://l2.io/ip.js?var=userip"></script>
<script scr="http://www.geoplugin.net/json.gp?ip="+userip+"&jsoncallback=callback"></script>
Or install your own Maxmind.com plugin :
http://dev.maxmind.com/geoip/legacy/geolite/
NOTE: You can get the IP via a PHP file and an AJAX request like here
https://stackoverflow.com/questions/1641868/how-to-get-client-ip-address-using-jquery
Google API
You will need a google API key, every informations here:
http://www.adammcfarland.com/2009/11/19/simple-ip-geolocation-using-javascript-and-the-google-ajax-search-api/