|Finding a user's location|
Trying to find the city where the user is located
I'm hoping you guys can help me figure out a way to determine a user's city or county (99.9% of our traffic is in the US). I'm sure that it can be done, since Google Analytics breaks down my traffic by city, but I can't figure out how to do it myself.
I tried using ipinfodb.com, but it's really not accurate for my area; I'm in western NC, but it lists me in Ohio. WHOIS for my IP shows that it's registered in Florida, so that's no good, either.
HTML5 Geolocation also misses me by about 200 miles, so that's pretty useless for my needs.
As a sort of last-ditch-effort, I'm searching the hostname for each county's name manually, in the hopes that their IP provider has the county's name. That only catches 1 in 10 users, though ("Embarq" and "Time Warner Cable" are big providers, and don't have the county name in the hostname), so it helps, but not a lot.
Any other suggestions? I'm willing to pay for a database, but I'd rather roll my own script.
|Google Analytics breaks down my traffic by city .... HTML5 Geolocation also misses me by about 200 miles |
To be honest if HTML5 geolocation (ie. Google location services, depending on browser) is not accurate for you then I struggle to see how Google Analytics will be any more accurate?
Out of curiosity, have you tried different browsers, in terms of HTML5 Geolocation? Chrome, Firefox, ...?
The HTML5 geolocation "position" object should return an "accuracy" (in metres) - position.coords.accuracy - how accurate does it "think" your location is?
Have you tried setting enableHighAccuracy to true - does it make any difference?
[edited by: penders at 3:50 pm (utc) on May 27, 2014]
I've used MaxMind's IP database. They have databases and web services. The free version may not be sufficient for your pruposes, but you can give it a shot.
If WHOIS shows error data, then there is nothing you can do.
If you are behind a proxy, disable it.
Else, I think your ISP provides boggus/false data.