Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    101
    Thanks
    14
    Thanked 1 Time in 1 Post

    Question How to get the browser's location (state)?

    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/do...ngUserLocation
    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!

  • #2
    New Coder
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    80
    Thanks
    1
    Thanked 8 Times in 8 Posts
    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

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Posts
    101
    Thanks
    14
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Truffle View Post
    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!

  • #4
    New Coder
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    80
    Thanks
    1
    Thanked 8 Times in 8 Posts
    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
    Last edited by Truffle; 11-17-2011 at 08:09 PM.

  • #5
    Regular Coder
    Join Date
    Mar 2009
    Posts
    101
    Thanks
    14
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Truffle View Post
    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. :-/

  • #6
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    Quote Originally Posted by Mechphisto View Post
    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'


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •