I have a website which checks users IP and if its from CA displays a message.
I am using JQuery to check users IP, the code is at http://jquery-howto.blogspot.in/2009/04/get-geographical-location-geolocation.html
I have implemented the code in my website
My question is :
How do i check if the code works ? Because i am not based in California
The sample code they give there does return state. Note that they give a new URL:
// Utilize the JSONP API
$.getJSON('http://www.geoplugin.net/json.gp?jsoncallback=?', function(data){
var region = data['geoplugin_region'];
var country = data['geoplugin_countryCode'];
if(country == 'US' && region == 'CA')
{
console.log("In CA");
}
else
{
console.log("In " + region + ", " + country);
}
});
This is not the only API you can use by any means.
Geolocation is not 100% accurate (for example, almost all AOL users look like they're in Virginia).
If you can accept that imperfection, there are many web services and downloadable databases out there that will geolocate the IP.
I have had good experience with MaxMind (they are not the most accurate, but they are quite accurate for the price, and they seem to have a free version now that is "less accurate" than the paid product).
A quick Google search will turn up many other alternatives, including
Be sure to review the terms of service of whichever you select.