...

View Full Version : How to get the browser's location (state)?



Mechphisto
11-17-2011, 04:51 PM
Hello,
We need to get a really good idea of what state (of the U.S.) the visitor to our Web site is browsing from. We realize it can't be perfect, but we just need to get a good idea. Our host's logs/analytics isn't that granular, so I'm hoping to add some scripting into our site to pull it.

Is there something better than $_SERVER['REMOTE_ADDR'], because that seems to give incorrect info a lot! We kind of want to get incorrect info just occasionally. :)

I see that Google Maps is doing something where they can locate you extremely accurately! I looked into it:
https://code.google.com/apis/maps/documentation/javascript/basics.html#DetectingUserLocation
but I can't reverse engineer this so that all it does is output as a string the state. I don't want the map, just to be able to pull the state so I can stick it into a database.

tl;dr: Can anyone point me to some example script that will allow me, with reasonable accuracy, to get the state of the U.S. the browser is in?

Thanks!

Truffle
11-17-2011, 06:39 PM
Not sure what the policy here is on posting links but google

"ip geolocation api"

The first result has an api that you can use with PHP code examples

Mechphisto
11-17-2011, 07:57 PM
Not sure what the policy here is on posting links but google

"ip geolocation api"

The first result has an api that you can use with PHP code examples

Thanks for the suggestion!
...but that's not going to work because it uses one's IP address to "locate." When I use their sample, it placed my public IP in the wrong state.

Somehow, Google's geolocation service can actually place me in the right state and even city! I don't know how, but I'd like to use it. But that's where I have the problem of trying to figure out how to use their example code to just parse the state and not have to use the map and all that.

Thanks for the reply!

Truffle
11-17-2011, 08:21 PM
They are using navigator.geolocation which is javascript and the data is only provided to you by the user if they wish to disclose it.
https://developer.mozilla.org/en/Using_geolocation

So, I think that API may only be useful for mobile devices with GPS because I don't see anywhere on my pc in my browser settings where I can actually set my latitude and longitude coordinates.

For desktop pcs the only way to do it is through IP geolocation and it is fairly accurate but most of the time it wont tell you where you are but where your ISP is

Mechphisto
11-17-2011, 10:15 PM
For desktop pcs the only way to do it is through IP geolocation and it is fairly accurate but most of the time it wont tell you where you are but where your ISP is

I'm on a PC. This seems to work great:
http://www.iplocationtools.com/api.html#b as it puts me exactly in the right city and state. It must be doing more than just SERVER information parsing, because anything I use that does that, puts me in the wrong state (where, presumably, my ISP is).
Now, this looks like it'll work for me... but I'd rather find an alternative that doesn't require me to display a banner ad for them. :-/

Adee
11-17-2011, 10:18 PM
I'm on a PC. This seems to work great:
http://www.iplocationtools.com/api.html#b as it puts me exactly in the right city and state. It must be doing more than just SERVER information parsing, because anything I use that does that, puts me in the wrong state (where, presumably, my ISP is).
Now, this looks like it'll work for me... but I'd rather find an alternative that doesn't require me to display a banner ad for them. :-/

they have a database it has nothing to do with 'information parsing'



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum